diff options
author | The Android Open Source Project <initial-contribution@android.com> | 2008-12-17 18:03:55 -0800 |
---|---|---|
committer | The Android Open Source Project <initial-contribution@android.com> | 2008-12-17 18:03:55 -0800 |
commit | dd828f42a5c83b4270d4fbf6fce2da1878f1e84a (patch) | |
tree | fdd4b68fa1020f2b6426034c94823419a7236200 /nio_char/src | |
parent | fdb2704414a9ed92394ada0d1395e4db86889465 (diff) | |
download | libcore-dd828f42a5c83b4270d4fbf6fce2da1878f1e84a.zip libcore-dd828f42a5c83b4270d4fbf6fce2da1878f1e84a.tar.gz libcore-dd828f42a5c83b4270d4fbf6fce2da1878f1e84a.tar.bz2 |
Code drop from //branches/cupcake/...@124589
Diffstat (limited to 'nio_char/src')
54 files changed, 3215 insertions, 534 deletions
diff --git a/nio_char/src/main/java/java/nio/charset/CharacterCodingException.java b/nio_char/src/main/java/java/nio/charset/CharacterCodingException.java index 7a9773f..a6c04bc 100644 --- a/nio_char/src/main/java/java/nio/charset/CharacterCodingException.java +++ b/nio_char/src/main/java/java/nio/charset/CharacterCodingException.java @@ -20,20 +20,23 @@ package java.nio.charset; import java.io.IOException; /** + * A {@code CharacterCodingException} is thrown when an encoding or decoding + * error occurs. * - * Type of exception thrown when an encoding or decoding error occurs. - * + * @since Android 1.0 */ public class CharacterCodingException extends IOException { /* - * This constant is used during deserialization to check the J2SE version + * This constant is used during deserialization to check the version * which created the serialized object. */ private static final long serialVersionUID = 8421532232154627783L; /** - * Default constructor. + * Constructs a new {@code CharacterCodingException}. + * + * @since Android 1.0 */ public CharacterCodingException() { super(); diff --git a/nio_char/src/main/java/java/nio/charset/Charset.java b/nio_char/src/main/java/java/nio/charset/Charset.java index 4274b26..045f71f 100644 --- a/nio_char/src/main/java/java/nio/charset/Charset.java +++ b/nio_char/src/main/java/java/nio/charset/Charset.java @@ -42,17 +42,17 @@ import com.ibm.icu4jni.charset.CharsetProviderICU; /** * A charset defines a mapping between a Unicode character sequence and a byte - * sequence. It facilitate the encoding from a Unicode character sequence into a - * byte sequence, and the decoding from a byte sequence into a Unicode character - * sequence. + * sequence. It facilitates the encoding from a Unicode character sequence into + * a byte sequence, and the decoding from a byte sequence into a Unicode + * character sequence. * <p> - * A charset has a canonical name, which are usually in uppercase. Typically it + * A charset has a canonical name, which is usually in uppercase. Typically it * also has one or more aliases. The name string can only consist of the * following characters: '0' - '9', 'A' - 'Z', 'a' - 'z', '.', ':'. '-' and '_'. * The first character of the name must be a digit or a letter. * </p> * <p> - * The following charsets should be supported by any java platforms: US-ASCII, + * The following charsets should be supported by any java platform: US-ASCII, * ISO-8859-1, UTF-8, UTF-16BE, UTF-16LE, UTF-16. * </p> * <p> @@ -61,19 +61,20 @@ import com.ibm.icu4jni.charset.CharsetProviderICU; * as "java.nio.charset.spi.CharsetProvider" and located in the * "META-INF/services" sub folder of one or more classpaths. The files should be * encoded in "UTF-8". Each line of their content specifies the class name of a - * charset provider which extends <code>java.nio.spi.CharsetProvider</code>. - * A line should ends with '\r', '\n' or '\r\n'. Leading and trailing - * whitespaces are trimmed. Blank lines, and lines (after trimmed) starting with - * "#" which are regarded as comments, are both ignored. Duplicates of already - * appeared names are also ignored. Both the configuration files and the - * provider classes will be loaded using the thread context class loader. + * charset provider which extends + * <code>java.nio.charset.spi.CharsetProvider</code>. A line should end with + * '\r', '\n' or '\r\n'. Leading and trailing whitespaces are trimmed. Blank + * lines, and lines (after trimming) starting with "#" which are regarded as + * comments, are both ignored. Duplicates of names already found are also + * ignored. Both the configuration files and the provider classes will be loaded + * using the thread context class loader. * </p> * <p> * This class is thread-safe. * </p> * * @see java.nio.charset.spi.CharsetProvider - * + * @since Android 1.0 */ public abstract class Charset implements Comparable<Charset> { @@ -162,14 +163,14 @@ public abstract class Charset implements Comparable<Charset> { * ignored. * * @param canonicalName - * the canonical name of the charset + * the canonical name of the charset. * @param aliases - * an array containing all aliases of the charset + * an array containing all aliases of the charset. May be null. * @throws IllegalCharsetNameException * on an illegal value being supplied for either * <code>canonicalName</code> or for any element of * <code>aliases</code>. - * + * @since Android 1.0 */ protected Charset(String canonicalName, String[] aliases) throws IllegalCharsetNameException { @@ -205,16 +206,16 @@ public abstract class Charset implements Comparable<Charset> { } /* - * Checks whether a character is a letter (ascii) which are defined in Java - * Spec. + * Checks whether a character is a letter (ascii) which are defined in the + * spec. */ private static boolean isLetter(char c) { return ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z'); } /* - * Checks whether a character is a digit (ascii) which are defined in Java - * Spec. + * Checks whether a character is a digit (ascii) which are defined in the + * spec. */ private static boolean isDigit(char c) { return ('0' <= c && c <= '9'); @@ -365,7 +366,8 @@ public abstract class Charset implements Comparable<Charset> { * </p> * * @return an unmodifiable map of all available charsets supported by the - * runtime + * runtime. + * @since Android 1.0 */ @SuppressWarnings("unchecked") public static SortedMap<String, Charset> availableCharsets() { @@ -441,17 +443,23 @@ public abstract class Charset implements Comparable<Charset> { systemClassLoader); cp = c.newInstance(); } catch (SecurityException e) { - throw e; + // BEGIN android-changed + // ignore + // END android-changed } catch (Exception e) { throw new Error(e.getMessage(), e); } } - // Try to get the desired charset from this provider - Charset cs = ((CharsetProvider) cp) - .charsetForName(charsetName); - if (null != cs) { - return cs; + // BEGIN android-changed + if (cp != null) { + // Try to get the desired charset from this provider + Charset cs = ((CharsetProvider) cp) + .charsetForName(charsetName); + if (null != cs) { + return cs; + } } + // END android-changed } // Read the next line of the config file providerClassName = reader.readLine(); @@ -549,12 +557,13 @@ public abstract class Charset implements Comparable<Charset> { * Gets a <code>Charset</code> instance for the specified charset name. * * @param charsetName - * the name of the charset - * @return a <code>Charset</code> instance for the specified charset name + * the canonical name of the charset or an alias. + * @return a <code>Charset</code> instance for the specified charset name. * @throws IllegalCharsetNameException - * If the specified charset name is illegal. + * if the specified charset name is illegal. * @throws UnsupportedCharsetException - * If the desired charset is not supported by this runtime. + * if the desired charset is not supported by this runtime. + * @since Android 1.0 */ public static Charset forName(String charsetName) throws IllegalCharsetNameException, UnsupportedCharsetException { @@ -569,10 +578,11 @@ public abstract class Charset implements Comparable<Charset> { * Determines whether the specified charset is supported by this runtime. * * @param charsetName - * the name of the charset - * @return true if the specified charset is supported, otherwise false + * the name of the charset. + * @return true if the specified charset is supported, otherwise false. * @throws IllegalCharsetNameException - * If the specified charset name is illegal. + * if the specified charset name is illegal. + * @since Android 1.0 */ public static boolean isSupported(String charsetName) throws IllegalCharsetNameException { @@ -584,23 +594,27 @@ public abstract class Charset implements Comparable<Charset> { * Determines whether this charset is a super set of the given charset. * * @param charset - * a given charset + * a given charset. * @return true if this charset is a super set of the given charset, - * otherwise false + * false if it's unknown or this charset is not a superset of + * the given charset. + * @since Android 1.0 */ public abstract boolean contains(Charset charset); /** - * Gets a new instance of encoder for this charset. + * Gets a new instance of an encoder for this charset. * - * @return a new instance of encoder for this charset + * @return a new instance of an encoder for this charset. + * @since Android 1.0 */ public abstract CharsetEncoder newEncoder(); /** - * Gets a new instance of decoder for this charset. + * Gets a new instance of a decoder for this charset. * - * @return a new instance of decoder for this charset + * @return a new instance of a decoder for this charset. + * @since Android 1.0 */ public abstract CharsetDecoder newDecoder(); @@ -608,6 +622,7 @@ public abstract class Charset implements Comparable<Charset> { * Gets the canonical name of this charset. * * @return this charset's name in canonical form. + * @since Android 1.0 */ public final String name() { return this.canonicalName; @@ -616,7 +631,8 @@ public abstract class Charset implements Comparable<Charset> { /** * Gets the set of this charset's aliases. * - * @return an unmodifiable set of this charset's aliases + * @return an unmodifiable set of this charset's aliases. + * @since Android 1.0 */ public final Set<String> aliases() { return Collections.unmodifiableSet(this.aliasesSet); @@ -625,7 +641,12 @@ public abstract class Charset implements Comparable<Charset> { /** * Gets the name of this charset for the default locale. * - * @return the name of this charset for the default locale + * This is the default implementation of this method which always returns + * the canonical name of this charset. Subclasses overriding this Method + * may return a display name that was localized. + * + * @return the name of this charset for the default locale. + * @since Android 1.0 */ public String displayName() { return this.canonicalName; @@ -634,20 +655,26 @@ public abstract class Charset implements Comparable<Charset> { /** * Gets the name of this charset for the specified locale. * + * This is the default implementation of this method which always returns + * the canonical name of this charset. Subclasses overriding this Method + * may return a display name that was localized. + * * @param l * a certain locale - * @return the name of this charset for the specified locale + * @return the name of this charset for the specified locale. + * @since Android 1.0 */ public String displayName(Locale l) { return this.canonicalName; } /** - * Returns whether this charset is known to be registered in the IANA + * Indicates whether this charset is known to be registered in the IANA * Charset Registry. * * @return true if the charset is known to be registered, otherwise returns * false. + * @since Android 1.0 */ public final boolean isRegistered() { return !canonicalName.startsWith("x-") //$NON-NLS-1$ @@ -655,9 +682,10 @@ public abstract class Charset implements Comparable<Charset> { } /** - * Returns true if this charset supports encoding, otherwise false. + * Returns true if this charset supports encoding, false otherwise. * - * @return true + * @return true if this charset supports encoding, false otherwise. + * @since Android 1.0 */ public boolean canEncode() { return true; @@ -672,8 +700,9 @@ public abstract class Charset implements Comparable<Charset> { * </p> * * @param buffer - * the character buffer containing the content to be encoded - * @return the result of the encoding + * the character buffer containing the content to be encoded. + * @return the result of the encoding. + * @since Android 1.0 */ synchronized public final ByteBuffer encode(CharBuffer buffer) { CharsetEncoder e = getCachedCharsetEncoder(canonicalName); @@ -711,24 +740,26 @@ public abstract class Charset implements Comparable<Charset> { * </p> * * @param s - * the string to be encoded - * @return the result of the encoding + * the string to be encoded. + * @return the result of the encoding. + * @since Android 1.0 */ public final ByteBuffer encode(String s) { return encode(CharBuffer.wrap(s)); } /** - * Decodes the content of the give byte buffer and outputs to a character - * buffer that is to be returned. + * Decodes the content of the specified byte buffer and writes it to a + * character buffer that is to be returned. * <p> * The default action in case of decoding errors is * <code>CodingErrorAction.REPLACE</code>. * </p> * * @param buffer - * the byte buffer containing the content to be decoded - * @return a character buffer containing the output of the decoding + * the byte buffer containing the content to be decoded. + * @return a character buffer containing the output of the decoding. + * @since Android 1.0 */ public final CharBuffer decode(ByteBuffer buffer) { CharsetDecoder d = getCachedCharsetDecoder(canonicalName); @@ -765,12 +796,14 @@ public abstract class Charset implements Comparable<Charset> { */ /** - * Compares this charset with the given charset. + * Compares this charset with the given charset. This comparation is + * based on the case insensitive canonical names of the charsets. * * @param charset - * the given object to be compared with + * the given object to be compared with. * @return a negative integer if less than the given object, a positive - * integer if larger than it, or 0 if equal to it + * integer if larger than it, or 0 if equal to it. + * @since Android 1.0 */ public final int compareTo(Charset charset) { return this.canonicalName.compareToIgnoreCase(charset.canonicalName); @@ -787,8 +820,9 @@ public abstract class Charset implements Comparable<Charset> { * considered to be equal if they have the same canonical name. * * @param obj - * the given object to be compared with - * @return true if they have the same canonical name, otherwise false + * the given object to be compared with. + * @return true if they have the same canonical name, otherwise false. + * @since Android 1.0 */ @Override public final boolean equals(Object obj) { @@ -802,7 +836,8 @@ public abstract class Charset implements Comparable<Charset> { /** * Gets the hash code of this charset. * - * @return the hash code of this charset + * @return the hash code of this charset. + * @since Android 1.0 */ @Override public final int hashCode() { @@ -813,7 +848,8 @@ public abstract class Charset implements Comparable<Charset> { * Gets a string representation of this charset. Usually this contains the * canonical name of the charset. * - * @return a string representation of this charset + * @return a string representation of this charset. + * @since Android 1.0 */ @Override public final String toString() { @@ -821,9 +857,10 @@ public abstract class Charset implements Comparable<Charset> { } /** - * Gets the system default charset from jvm. + * Gets the system default charset from the virtual machine. * - * @return the default charset + * @return the default charset. + * @since Android 1.0 */ public static Charset defaultCharset() { Charset defaultCharset = null; diff --git a/nio_char/src/main/java/java/nio/charset/CharsetDecoder.java b/nio_char/src/main/java/java/nio/charset/CharsetDecoder.java index 5c1be6e..38fb9b2 100644 --- a/nio_char/src/main/java/java/nio/charset/CharsetDecoder.java +++ b/nio_char/src/main/java/java/nio/charset/CharsetDecoder.java @@ -24,45 +24,45 @@ import java.nio.CharBuffer; import org.apache.harmony.niochar.internal.nls.Messages; /** - * An converter that can convert bytes sequence in some charset to 16-bit + * A converter that can convert a byte sequence from a charset into a 16-bit * Unicode character sequence. * <p> - * The input byte sequence is wrapped by {@link java.nio.ByteBuffer ByteBuffer} - * and the output character sequence is {@link java.nio.CharBuffer CharBuffer}. - * A decoder instance should be used in following sequence, which is referred to - * as a decoding operation: + * The input byte sequence is wrapped by a + * {@link java.nio.ByteBuffer ByteBuffer} and the output character sequence is a + * {@link java.nio.CharBuffer CharBuffer}. A decoder instance should be used in + * the following sequence, which is referred to as a decoding operation: * <ol> - * <li>Invoking the {@link #reset() reset} method to reset the decoder if the + * <li>invoking the {@link #reset() reset} method to reset the decoder if the * decoder has been used;</li> - * <li>Invoking the {@link #decode(ByteBuffer, CharBuffer, boolean) decode} + * <li>invoking the {@link #decode(ByteBuffer, CharBuffer, boolean) decode} * method until the additional input is not needed, the <code>endOfInput</code> * parameter must be set to false, the input buffer must be filled and the * output buffer must be flushed between invocations;</li> - * <li>Invoking the {@link #decode(ByteBuffer, CharBuffer, boolean) decode} - * method last time, and the the <code>endOfInput</code> parameter must be set - * to true</li> - * <li>Invoking the {@link #flush(CharBuffer) flush} method to flush the + * <li>invoking the {@link #decode(ByteBuffer, CharBuffer, boolean) decode} + * method for the last time, and then the <code>endOfInput</code> parameter + * must be set to true;</li> + * <li>invoking the {@link #flush(CharBuffer) flush} method to flush the * output.</li> * </ol> * </p> * <p> * The {@link #decode(ByteBuffer, CharBuffer, boolean) decode} method will - * convert as many bytes as possible, and the process won't stop except the - * input bytes has been run out of, the output buffer has been filled or some - * error has happened. A {@link CoderResult CoderResult} instance will be - * returned to indicate the stop reason, and the invoker can identify the result - * and choose further action, which can include filling the input buffer, - * flushing the output buffer, recovering from error and trying again. + * convert as many bytes as possible, and the process won't stop until the input + * bytes have run out, the output buffer has been filled or some error has + * happened. A {@link CoderResult CoderResult} instance will be returned to + * indicate the stop reason, and the invoker can identify the result and choose + * further action, which includes filling the input buffer, flushing the output + * buffer or recovering from an error and trying again. * </p> * <p> - * There are two common decoding errors. One is named as malformed and it is - * returned when the input byte sequence is illegal for current specific - * charset, the other is named as unmappable character and it is returned when a + * There are two common decoding errors. One is named malformed and it is + * returned when the input byte sequence is illegal for the current specific + * charset, the other is named unmappable character and it is returned when a * problem occurs mapping a legal input byte sequence to its Unicode character * equivalent. * </p> * <p> - * The two errors can be handled in three ways, the default one is to report the + * Both errors can be handled in three ways, the default one is to report the * error to the invoker by a {@link CoderResult CoderResult} instance, and the * alternatives are to ignore it or to replace the erroneous input with the * replacement string. The replacement string is "\uFFFD" by default and can be @@ -74,12 +74,12 @@ import org.apache.harmony.niochar.internal.nls.Messages; * method. * </p> * <p> - * This class is abstract class and encapsulate many common operations of - * decoding process for all charsets. Decoder for specific charset should extend - * this class and need only implement - * {@link #decodeLoop(ByteBuffer, CharBuffer) decodeLoop} method for basic - * decoding loop. If a subclass maintains internal state, it should override the - * {@link #implFlush(CharBuffer) implFlush} method and + * This is an abstract class and encapsulates many common operations of the + * decoding process for all charsets. Decoders for a specific charset should + * extend this class and need only to implement the + * {@link #decodeLoop(ByteBuffer, CharBuffer) decodeLoop} method for the basic + * decoding. If a subclass maintains an internal state, it should override the + * {@link #implFlush(CharBuffer) implFlush} method and the * {@link #implReset() implReset} method in addition. * </p> * <p> @@ -88,6 +88,7 @@ import org.apache.harmony.niochar.internal.nls.Messages; * * @see java.nio.charset.Charset * @see java.nio.charset.CharsetEncoder + * @since Android 1.0 */ public abstract class CharsetDecoder { /* @@ -135,23 +136,23 @@ public abstract class CharsetDecoder { * --------------------------------------- */ /** - * Construct a new <code>CharsetDecoder</code> using given + * Constructs a new <code>CharsetDecoder</code> using the given * <code>Charset</code>, average number and maximum number of characters * created by this decoder for one input byte, and the default replacement * string "\uFFFD". * * @param charset - * this decoder's <code>Charset</code>, which create this - * decoder + * the <code>Charset</code> to be used by this decoder. * @param averageCharsPerByte - * average number of characters created by this decoder for one - * input byte, must be positive + * the average number of characters created by this decoder for + * one input byte, must be positive. * @param maxCharsPerByte - * maximum number of characters created by this decoder for one - * input byte, must be positive + * the maximum number of characters created by this decoder for + * one input byte, must be positive. * @throws IllegalArgumentException * if <code>averageCharsPerByte</code> or - * <code>maxCharsPerByte</code> is negative + * <code>maxCharsPerByte</code> is negative. + * @since Android 1.0 */ protected CharsetDecoder(Charset charset, float averageCharsPerByte, float maxCharsPerByte) { @@ -177,57 +178,62 @@ public abstract class CharsetDecoder { * --------------------------------------- */ /** - * get the average number of characters created by this decoder for single - * input byte + * Gets the average number of characters created by this decoder for a + * single input byte. * - * @return the average number of characters created by this decoder for - * single input byte + * @return the average number of characters created by this decoder for a + * single input byte. + * @since Android 1.0 */ public final float averageCharsPerByte() { return averChars; } /** - * Get the <code>Charset</code> which creates this decoder. + * Gets the <code>Charset</code> which this decoder uses. * - * @return the <code>Charset</code> which creates this decoder + * @return the <code>Charset</code> which this decoder uses. + * @since Android 1.0 */ public final Charset charset() { return cs; } /** - * This is a facade method for decoding operation. + * This is a facade method for the decoding operation. * <p> * This method decodes the remaining byte sequence of the given byte buffer * into a new character buffer. This method performs a complete decoding * operation, resets at first, then decodes, and flushes at last. * </p> * <p> - * This method should not be invoked if another decode operation is ongoing. + * This method should not be invoked while another {@code decode} operation + * is ongoing. * </p> * * @param in - * the input buffer + * the input buffer. * @return a new <code>CharBuffer</code> containing the the characters * produced by this decoding operation. The buffer's limit will be - * the position of last character in buffer, and the position will - * be zero + * the position of the last character in the buffer, and the + * position will be zero. * @throws IllegalStateException - * if another decoding operation is ongoing + * if another decoding operation is ongoing. * @throws MalformedInputException - * if illegal input byte sequence for this charset encountered, - * and the action for malformed error is + * if an illegal input byte sequence for this charset was + * encountered, and the action for malformed error is * {@link CodingErrorAction#REPORT CodingErrorAction.REPORT} * @throws UnmappableCharacterException - * if legal but unmappable input byte sequence for this charset - * encountered, and the action for unmappable character error is + * if a legal but unmappable input byte sequence for this + * charset was encountered, and the action for unmappable + * character error is * {@link CodingErrorAction#REPORT CodingErrorAction.REPORT}. * Unmappable means the byte sequence at the input buffer's * current position cannot be mapped to a Unicode character * sequence. * @throws CharacterCodingException - * if other exception happened during the decode operation + * if another exception happened during the decode operation. + * @since Android 1.0 */ public final CharBuffer decode(ByteBuffer in) throws CharacterCodingException { @@ -313,49 +319,51 @@ public abstract class CharsetDecoder { * operation may be regarded as complete. Otherwise, this method should be * called once more with additional input.</li> * <li>A {@link CoderResult#malformedForLength(int) malformed input} result - * indicates that some malformed input error encountered, and the erroneous - * bytes start at the input buffer's position and their number can be got by - * result's {@link CoderResult#length() length}. This kind of result can be - * returned only if the malformed action is + * indicates that some malformed input error has been encountered, and the + * erroneous bytes start at the input buffer's position and their number can + * be got by result's {@link CoderResult#length() length}. This kind of + * result can be returned only if the malformed action is * {@link CodingErrorAction#REPORT CodingErrorAction.REPORT}. </li> * <li>A {@link CoderResult#unmappableForLength(int) unmappable character} - * result indicates that some unmappable character error encountered, and - * the erroneous bytes start at the input buffer's position and their number - * can be got by result's {@link CoderResult#length() length}. This kind of - * result can be returned only if the unmappable character action is + * result indicates that some unmappable character error has been + * encountered, and the erroneous bytes start at the input buffer's position + * and their number can be got by result's + * {@link CoderResult#length() length}. This kind of result can be returned + * only if the unmappable character action is * {@link CodingErrorAction#REPORT CodingErrorAction.REPORT}. </li> * </ul> * </p> * <p> - * The <code>endOfInput</code> parameter indicates that if the invoker can - * provider further input. This parameter is true if and only if the bytes - * in current input buffer are all inputs for this decoding operation. Note - * that it is common and won't cause error that the invoker sets false and - * then finds no more input available; while it may cause error that the - * invoker always sets true in several consecutive invocations so that any - * remaining input will be treated as malformed input. + * The <code>endOfInput</code> parameter indicates that the invoker cannot + * provide further input. This parameter is true if and only if the bytes in + * current input buffer are all inputs for this decoding operation. Note + * that it is common and won't cause an error if the invoker sets false and + * then can't provide more input, while it may cause an error if the invoker + * always sets true in several consecutive invocations. This would make the + * remaining input to be treated as malformed input. * </p> * <p> - * This method invokes + * This method invokes the * {@link #decodeLoop(ByteBuffer, CharBuffer) decodeLoop} method to - * implement basic decode logic for specific charset. + * implement the basic decode logic for a specific charset. * </p> * * @param in - * the input buffer + * the input buffer. * @param out - * the output buffer + * the output buffer. * @param endOfInput - * true if all the input characters have been provided + * true if all the input characters have been provided. * @return a <code>CoderResult</code> instance which indicates the reason - * of termination + * of termination. * @throws IllegalStateException * if decoding has started or no more input is needed in this * decoding progress. * @throws CoderMalfunctionError * if the {@link #decodeLoop(ByteBuffer, CharBuffer) decodeLoop} * method threw an <code>BufferUnderflowException</code> or - * <code>BufferOverflowException</code> + * <code>BufferOverflowException</code>. + * @since Android 1.0 */ public final CoderResult decode(ByteBuffer in, CharBuffer out, boolean endOfInput) { @@ -413,102 +421,115 @@ public abstract class CharsetDecoder { return result; } if (!result.isMalformed()) { + // Note: the following condition is removed in Harmony revision 518047 + // However, making the conditional statement unconditional + // leads to misbehavior when using REPLACE on malformedInput. in.position(in.position() + result.length()); } } } /** - * Decode bytes into characters. This method is called by + * Decodes bytes into characters. This method is called by the * {@link #decode(ByteBuffer, CharBuffer, boolean) decode} method. - * + * <p> * This method will implement the essential decoding operation, and it won't * stop decoding until either all the input bytes are read, the output - * buffer is filled, or some exception encountered. And then it will return - * a <code>CoderResult</code> object indicating the result of current + * buffer is filled, or some exception is encountered. Then it will return a + * <code>CoderResult</code> object indicating the result of current * decoding operation. The rules to construct the <code>CoderResult</code> - * is same as the {@link #decode(ByteBuffer, CharBuffer, boolean) decode}. - * When exception encountered in the decoding operation, most implementation - * of this method will return a relevant result object to + * are the same as for + * {@link #decode(ByteBuffer, CharBuffer, boolean) decode}. When an + * exception is encountered in the decoding operation, most implementations + * of this method will return a relevant result object to the * {@link #decode(ByteBuffer, CharBuffer, boolean) decode} method, and some * performance optimized implementation may handle the exception and * implement the error action itself. - * + * </p> + * <p> * The buffers are scanned from their current positions, and their positions * will be modified accordingly, while their marks and limits will be * intact. At most {@link ByteBuffer#remaining() in.remaining()} characters * will be read, and {@link CharBuffer#remaining() out.remaining()} bytes * will be written. - * - * Note that some implementation may pre-scan the input buffer and return + * </p> + * <p> + * Note that some implementations may pre-scan the input buffer and return a * <code>CoderResult.UNDERFLOW</code> until it receives sufficient input. + * </p> * * @param in - * the input buffer + * the input buffer. * @param out - * the output buffer - * @return a <code>CoderResult</code> instance indicating the result + * the output buffer. + * @return a <code>CoderResult</code> instance indicating the result. + * @since Android 1.0 */ protected abstract CoderResult decodeLoop(ByteBuffer in, CharBuffer out); /** - * Get the charset detected by this decoder, this method is optional. + * Gets the charset detected by this decoder; this method is optional. * <p> * If implementing an auto-detecting charset, then this decoder returns the * detected charset from this method when it is available. The returned * charset will be the same for the rest of the decode operation. * </p> * <p> - * If insufficient bytes have been read to determine the charset, + * If insufficient bytes have been read to determine the charset, an * <code>IllegalStateException</code> will be thrown. * </p> * <p> * The default implementation always throws * <code>UnsupportedOperationException</code>, so it should be overridden - * by subclass if needed. + * by a subclass if needed. * </p> * * @return the charset detected by this decoder, or null if it is not yet - * determined + * determined. * @throws UnsupportedOperationException - * if this decoder does not implement an auto-detecting charset + * if this decoder does not implement an auto-detecting charset. * @throws IllegalStateException - * if insufficient bytes have been read to determine the charset + * if insufficient bytes have been read to determine the + * charset. + * @since Android 1.0 */ public Charset detectedCharset() { throw new UnsupportedOperationException(); } /** - * Flush this decoder. + * Flushes this decoder. * * This method will call {@link #implFlush(CharBuffer) implFlush}. Some * decoders may need to write some characters to the output buffer when they - * have read all input bytes, subclasses can overridden - * {@link #implFlush(CharBuffer) implFlush} to perform writing action. - * - * The maximum number of written bytes won't larger than - * {@link CharBuffer#remaining() out.remaining()}. If some decoder want to - * write more bytes than output buffer's remaining spaces, then + * have read all input bytes; subclasses can override + * {@link #implFlush(CharBuffer) implFlush} to perform the writing operation. + * <p> + * The maximum number of written bytes won't be larger than + * {@link CharBuffer#remaining() out.remaining()}. If some decoder wants to + * write more bytes than an output buffer's remaining space allows, then a * <code>CoderResult.OVERFLOW</code> will be returned, and this method - * must be called again with a character buffer that has more spaces. - * Otherwise this method will return <code>CoderResult.UNDERFLOW</code>, - * which means one decoding process has been completed successfully. - * + * must be called again with a character buffer that has more remaining + * space. Otherwise this method will return + * <code>CoderResult.UNDERFLOW</code>, which means one decoding process + * has been completed successfully. + * </p> + * <p> * During the flush, the output buffer's position will be changed * accordingly, while its mark and limit will be intact. - * + * </p> * @param out - * the given output buffer + * the given output buffer. * @return <code>CoderResult.UNDERFLOW</code> or - * <code>CoderResult.OVERFLOW</code> + * <code>CoderResult.OVERFLOW</code>. * @throws IllegalStateException * if this decoder hasn't read all input bytes during one * decoding process, which means neither after calling * {@link #decode(ByteBuffer) decode(ByteBuffer)} nor after * calling {@link #decode(ByteBuffer, CharBuffer, boolean) - * decode(ByteBuffer, CharBuffer, boolean)} with true value for - * the last boolean parameter + * decode(ByteBuffer, CharBuffer, boolean)} with true as value + * for the last boolean parameter. + * @since Android 1.0 */ public final CoderResult flush(CharBuffer out) { if (status != END && status != INIT) { @@ -522,79 +543,88 @@ public abstract class CharsetDecoder { } /** - * Flush this decoder. Default implementation does nothing and always return - * <code>CoderResult.UNDERFLOW</code>, and this method can be overridden - * if needed. + * Flushes this decoder. The default implementation does nothing and always + * returns <code>CoderResult.UNDERFLOW</code>; this method can be + * overridden if needed. * * @param out - * the output buffer + * the output buffer. * @return <code>CoderResult.UNDERFLOW</code> or - * <code>CoderResult.OVERFLOW</code> + * <code>CoderResult.OVERFLOW</code>. + * @since Android 1.0 */ protected CoderResult implFlush(CharBuffer out) { return CoderResult.UNDERFLOW; } /** - * Notify that this decoder's <code>CodingErrorAction</code> specified for - * malformed input error has been changed. Default implementation does - * nothing, and this method can be overridden if needed. + * Notifies that this decoder's <code>CodingErrorAction</code> specified + * for malformed input error has been changed. The default implementation + * does nothing; this method can be overridden if needed. * * @param newAction - * The new action + * the new action. + * @since Android 1.0 */ protected void implOnMalformedInput(CodingErrorAction newAction) { // default implementation is empty } /** - * Notify that this decoder's <code>CodingErrorAction</code> specified for - * unmappable character error has been changed. Default implementation does - * nothing, and this method can be overridden if needed. + * Notifies that this decoder's <code>CodingErrorAction</code> specified + * for unmappable character error has been changed. The default + * implementation does nothing; this method can be overridden if needed. * * @param newAction - * The new action + * the new action. + * @since Android 1.0 */ protected void implOnUnmappableCharacter(CodingErrorAction newAction) { // default implementation is empty } /** - * Notify that this decoder's replacement has been changed. Default - * implementation does nothing, and this method can be overridden if needed. + * Notifies that this decoder's replacement has been changed. The default + * implementation does nothing; this method can be overridden if needed. * * @param newReplacement - * the new replacement string + * the new replacement string. + * @since Android 1.0 */ protected void implReplaceWith(String newReplacement) { // default implementation is empty } /** - * Reset this decoder's charset related state. Default implementation does - * nothing, and this method can be overridden if needed. + * Reset this decoder's charset related state. The default implementation + * does nothing; this method can be overridden if needed. + * + * @since Android 1.0 */ protected void implReset() { // default implementation is empty } /** - * Get if this decoder implements an auto-detecting charset. + * Indicates whether this decoder implements an auto-detecting charset. * * @return <code>true</code> if this decoder implements an auto-detecting - * charset + * charset. + * @since Android 1.0 */ public boolean isAutoDetecting() { return false; } /** - * Get if this decoder has detected a charset, this method is optional. + * Indicates whether this decoder has detected a charset; this method is + * optional. * <p> * If this decoder implements an auto-detecting charset, then this method * may start to return true during decoding operation to indicate that a * charset has been detected in the input bytes and that the charset can be - * retrieved by invoking {@link #detectedCharset() detectedCharset} method. + * retrieved by invoking the {@link #detectedCharset() detectedCharset} + * method. * </p> * <p> * Note that a decoder that implements an auto-detecting charset may still @@ -606,12 +636,13 @@ public abstract class CharsetDecoder { * <p> * The default implementation always throws an * <code>UnsupportedOperationException</code>; it should be overridden by - * subclass if needed. + * a subclass if needed. * </p> * - * @return <code>true</code> this decoder has detected a charset + * @return <code>true</code> if this decoder has detected a charset. * @throws UnsupportedOperationException - * if this decoder doesn't implement an auto-detecting charset + * if this decoder doesn't implement an auto-detecting charset. + * @since Android 1.0 */ public boolean isCharsetDetected() { throw new UnsupportedOperationException(); @@ -619,38 +650,41 @@ public abstract class CharsetDecoder { /** * Gets this decoder's <code>CodingErrorAction</code> when malformed input - * occurred during decoding process. + * occurred during the decoding process. * * @return this decoder's <code>CodingErrorAction</code> when malformed - * input occurred during decoding process. + * input occurred during the decoding process. + * @since Android 1.0 */ public CodingErrorAction malformedInputAction() { return malformAction; } /** - * Get the maximum number of characters which can be created by this decoder - * for one input byte, must be positive + * Gets the maximum number of characters which can be created by this + * decoder for one input byte, must be positive. * * @return the maximum number of characters which can be created by this - * decoder for one input byte, must be positive + * decoder for one input byte, must be positive. + * @since Android 1.0 */ public final float maxCharsPerByte() { return maxChars; } /** - * Set this decoder's action on malformed input error. + * Sets this decoder's action on malformed input errors. * * This method will call the * {@link #implOnMalformedInput(CodingErrorAction) implOnMalformedInput} * method with the given new action as argument. * * @param newAction - * the new action on malformed input error - * @return this decoder + * the new action on malformed input error. + * @return this decoder. * @throws IllegalArgumentException - * if the given newAction is null + * if {@code newAction} is {@code null}. + * @since Android 1.0 */ public final CharsetDecoder onMalformedInput(CodingErrorAction newAction) { if (null == newAction) { @@ -662,17 +696,18 @@ public abstract class CharsetDecoder { } /** - * Set this decoder's action on unmappable character error. + * Sets this decoder's action on unmappable character errors. * * This method will call the * {@link #implOnUnmappableCharacter(CodingErrorAction) implOnUnmappableCharacter} * method with the given new action as argument. * * @param newAction - * the new action on unmappable character error - * @return this decoder + * the new action on unmappable character error. + * @return this decoder. * @throws IllegalArgumentException - * if the given newAction is null + * if {@code newAction} is {@code null}. + * @since Android 1.0 */ public final CharsetDecoder onUnmappableCharacter( CodingErrorAction newAction) { @@ -685,28 +720,31 @@ public abstract class CharsetDecoder { } /** - * Get the replacement string, which is never null or empty + * Gets the replacement string, which is never null or empty. * - * @return the replacement string, cannot be null or empty + * @return the replacement string, cannot be null or empty. + * @since Android 1.0 */ public final String replacement() { return replace; } /** - * Set new replacement value. + * Sets the new replacement string. * * This method first checks the given replacement's validity, then changes - * the replacement value, and at last calls + * the replacement value, and at last calls the * {@link #implReplaceWith(String) implReplaceWith} method with the given * new replacement as argument. * * @param newReplacement - * the replacement string, cannot be null or empty - * @return this decoder + * the replacement string, cannot be null or empty. Its length + * cannot be larger than {@link #maxCharsPerByte()}. + * @return this decoder. * @throws IllegalArgumentException * if the given replacement cannot satisfy the requirement - * mentioned above + * mentioned above. + * @since Android 1.0 */ public final CharsetDecoder replaceWith(String newReplacement) { if (null == newReplacement || newReplacement.length() == 0) { @@ -724,11 +762,12 @@ public abstract class CharsetDecoder { } /** - * Reset this decoder. This method will reset internal status, and then call - * <code>implReset()</code> to reset any status related to specific - * charset. + * Resets this decoder. This method will reset the internal status, and then + * calls <code>implReset()</code> to reset any status related to the + * specific charset. * - * @return this decoder + * @return this decoder. + * @since Android 1.0 */ public final CharsetDecoder reset() { status = INIT; @@ -737,11 +776,12 @@ public abstract class CharsetDecoder { } /** - * Gets this decoder's <code>CodingErrorAction</code> when unmappable - * character occurred during decoding process. + * Gets this decoder's <code>CodingErrorAction</code> when an unmappable + * character error occurred during the decoding process. * - * @return this decoder's <code>CodingErrorAction</code> when unmappable - * character occurred during decoding process. + * @return this decoder's <code>CodingErrorAction</code> when an + * unmappable character error occurred during the decoding process. + * @since Android 1.0 */ public CodingErrorAction unmappableCharacterAction() { return unmapAction; diff --git a/nio_char/src/main/java/java/nio/charset/CharsetEncoder.java b/nio_char/src/main/java/java/nio/charset/CharsetEncoder.java index 0cb3fdc..24b8b3f 100644 --- a/nio_char/src/main/java/java/nio/charset/CharsetEncoder.java +++ b/nio_char/src/main/java/java/nio/charset/CharsetEncoder.java @@ -24,61 +24,62 @@ import java.nio.CharBuffer; import org.apache.harmony.niochar.internal.nls.Messages; /** - * An converter that can convert 16-bit Unicode character sequence to byte - * sequence in some charset . + * A converter that can converts a 16-bit Unicode character sequence to a byte + * sequence in some charset. * <p> - * The input character sequence is wrapped by - * {@link java.nio.CharBuffer CharBuffer} and the output character sequence is - * {@link java.nio.ByteBuffer ByteBuffer}. A encoder instance should be used in - * following sequence, which is referred to as a encoding operation: + * The input character sequence is wrapped by a + * {@link java.nio.CharBuffer CharBuffer} and the output character sequence is a + * {@link java.nio.ByteBuffer ByteBuffer}. An encoder instance should be used + * in the following sequence, which is referred to as a encoding operation: * <ol> - * <li>Invoking the {@link #reset() reset} method to reset the encoder if the + * <li>invoking the {@link #reset() reset} method to reset the encoder if the * encoder has been used;</li> - * <li>Invoking the {@link #encode(CharBuffer, ByteBuffer, boolean) encode} + * <li>invoking the {@link #encode(CharBuffer, ByteBuffer, boolean) encode} * method until the additional input is not needed, the <code>endOfInput</code> * parameter must be set to false, the input buffer must be filled and the * output buffer must be flushed between invocations;</li> - * <li>Invoking the {@link #encode(CharBuffer, ByteBuffer, boolean) encode} - * method last time, and the the <code>endOfInput</code> parameter must be set - * to true</li> - * <li>Invoking the {@link #flush(ByteBuffer) flush} method to flush the + * <li>invoking the {@link #encode(CharBuffer, ByteBuffer, boolean) encode} + * method for the last time and the <code>endOfInput</code> parameter must be + * set to {@code true}</li> + * <li>invoking the {@link #flush(ByteBuffer) flush} method to flush the * output.</li> * </ol> * </p> * <p> * The {@link #encode(CharBuffer, ByteBuffer, boolean) encode} method will - * convert as many characters as possible, and the process won't stop except the - * input characters has been run out of, the output buffer has been filled or - * some error has happened. A {@link CoderResult CoderResult} instance will be + * convert as many characters as possible, and the process won't stop until the + * input characters have run out, the output buffer has been filled or some + * error has happened. A {@link CoderResult CoderResult} instance will be * returned to indicate the stop reason, and the invoker can identify the result - * and choose further action, which can include filling the input buffer, - * flushing the output buffer, recovering from error and trying again. + * and choose further action, which includes filling the input buffer, flushing + * the output buffer or recovering from an error and trying again. * </p> * <p> - * There are two common encoding errors. One is named as malformed and it is - * returned when the input content is illegal 16-bit Unicode character sequence, - * the other is named as unmappable character and occurs when there is a problem - * mapping the input to a valid byte sequence in the specific charset. + * There are two common encoding errors. One is named malformed and it is + * returned when the input content is an illegal 16-bit Unicode character + * sequence, the other is named unmappable character and occurs when there is a + * problem mapping the input to a valid byte sequence in the specified charset. * </p> * <p> - * The two errors can be handled in three ways, the default one is to report the + * Both errors can be handled in three ways, the default one is to report the * error to the invoker by a {@link CoderResult CoderResult} instance, and the * alternatives are to ignore it or to replace the erroneous input with the - * replacement byte array. The replacement byte array is {(byte)'?'} by default - * and can be changed by invoking {@link #replaceWith(byte[]) replaceWith} - * method. The invoker of this encoder can choose one way by specifying a + * replacement byte array. The replacement byte array is '{@code ?}' by + * default and can be changed by invoking the + * {@link #replaceWith(byte[]) replaceWith} method. The invoker of this encoder + * can choose one way by specifying a * {@link CodingErrorAction CodingErrorAction} instance for each error type via - * {@link #onMalformedInput(CodingErrorAction) onMalformedInput} method and - * {@link #onUnmappableCharacter(CodingErrorAction) onUnmappableCharacter} + * the {@link #onMalformedInput(CodingErrorAction) onMalformedInput} method and + * the {@link #onUnmappableCharacter(CodingErrorAction) onUnmappableCharacter} * method. * </p> * <p> - * This class is abstract class and encapsulate many common operations of - * encoding process for all charsets. encoder for specific charset should extend - * this class and need only implement + * This class is abstract and encapsulates many common operations of the + * encoding process for all charsets. Encoders for a specific charset should + * extend this class and need only to implement the * {@link #encodeLoop(CharBuffer, ByteBuffer) encodeLoop} method for basic - * encoding loop. If a subclass maintains internal state, it should override the - * {@link #implFlush(ByteBuffer) implFlush} method and + * encoding. If a subclass maintains an internal state, it should override the + * {@link #implFlush(ByteBuffer) implFlush} method and the * {@link #implReset() implReset} method in addition. * </p> * <p> @@ -87,6 +88,7 @@ import org.apache.harmony.niochar.internal.nls.Messages; * * @see java.nio.charset.Charset * @see java.nio.charset.CharsetDecoder + * @since Android 1.0 */ public abstract class CharsetEncoder { /* @@ -139,22 +141,22 @@ public abstract class CharsetEncoder { */ /** - * Construct a new <code>CharsetEncoder</code> using given + * Constructs a new <code>CharsetEncoder</code> using the given * <code>Charset</code>, average number and maximum number of bytes * created by this encoder for one input character. * * @param cs - * this encoder's <code>Charset</code>, which create this - * encoder + * the <code>Charset</code> to be used by this encoder. * @param averageBytesPerChar * average number of bytes created by this encoder for one input - * character, must be positive + * character, must be positive. * @param maxBytesPerChar * maximum number of bytes which can be created by this encoder - * for one input character, must be positive + * for one input character, must be positive. * @throws IllegalArgumentException * if <code>maxBytesPerChar</code> or - * <code>averageBytePerChar</code> is negative + * <code>averageBytesPerChar</code> is negative. + * @since Android 1.0 */ protected CharsetEncoder(Charset cs, float averageBytesPerChar, float maxBytesPerChar) { @@ -163,26 +165,26 @@ public abstract class CharsetEncoder { } /** - * Construct a new <code>CharsetEncoder</code> using given - * <code>Charset</code>, replace byte array, average number and maximum - * number of bytes created by this encoder for one input character. + * Constructs a new <code>CharsetEncoder</code> using the given + * <code>Charset</code>, replacement byte array, average number and + * maximum number of bytes created by this encoder for one input character. * * @param cs - * the this encoder's <code>Charset</code>, which create this - * encoder + * the <code>Charset</code> to be used by this encoder. * @param averageBytesPerChar - * average number of bytes created by this encoder for single - * input character, must be positive + * average number of bytes created by this encoder for one single + * input character, must be positive. * @param maxBytesPerChar * maximum number of bytes which can be created by this encoder - * for single input character, must be positive + * for one single input character, must be positive. * @param replacement * the replacement byte array, cannot be null or empty, its - * length cannot larger than <code>maxBytesPerChar</code>, and - * must be legal replacement, which can be justified by - * {@link #isLegalReplacement(byte[]) isLegalReplacement} + * length cannot be larger than <code>maxBytesPerChar</code>, + * and must be a legal replacement, which can be justified by + * {@link #isLegalReplacement(byte[]) isLegalReplacement}. * @throws IllegalArgumentException - * if any parameters are invalid + * if any parameters are invalid. + * @since Android 1.0 */ protected CharsetEncoder(Charset cs, float averageBytesPerChar, float maxBytesPerChar, byte[] replacement) { @@ -208,31 +210,35 @@ public abstract class CharsetEncoder { * --------------------------------------- */ /** - * get the average number of bytes created by this encoder for single input - * character + * Gets the average number of bytes created by this encoder for a single + * input character. * - * @return the average number of bytes created by this encoder for single - * input character + * @return the average number of bytes created by this encoder for a single + * input character. + * @since Android 1.0 */ public final float averageBytesPerChar() { return averBytes; } /** - * Check if given character can be encoded by this encoder. - * + * Checks if the given character can be encoded by this encoder. + * <p> * Note that this method can change the internal status of this encoder, so - * it should not be called when another encode process is ongoing, otherwise - * it will throw <code>IllegalStateException</code>. - * + * it should not be called when another encoding process is ongoing, + * otherwise it will throw an <code>IllegalStateException</code>. + * </p> + * <p> * This method can be overridden for performance improvement. + * </p> * * @param c - * the given encoder - * @return true if given character can be encoded by this encoder + * the given encoder. + * @return true if given character can be encoded by this encoder. * @throws IllegalStateException - * if another encode process is ongoing so that current internal - * status is neither RESET or FLUSH + * if another encode process is ongoing so that the current + * internal status is neither RESET or FLUSH. + * @since Android 1.0 */ public boolean canEncode(char c) { return implCanEncode(CharBuffer.wrap(new char[] { c })); @@ -264,21 +270,22 @@ public abstract class CharsetEncoder { } /** - * Check if given <code>CharSequence</code> can be encoded by this + * Checks if a given <code>CharSequence</code> can be encoded by this * encoder. * * Note that this method can change the internal status of this encoder, so * it should not be called when another encode process is ongoing, otherwise - * it will throw <code>IllegalStateException</code>. + * it will throw an <code>IllegalStateException</code>. * * This method can be overridden for performance improvement. * * @param sequence - * the given <code>CharSequence</code> - * @return true if given <code>CharSequence</code> can be encoded by this - * encoder + * the given <code>CharSequence</code>. + * @return true if the given <code>CharSequence</code> can be encoded by + * this encoder. * @throws IllegalStateException - * if current internal status is neither RESET or FLUSH + * if current internal status is neither RESET or FLUSH. + * @since Android 1.0 */ public boolean canEncode(CharSequence sequence) { CharBuffer cb; @@ -291,16 +298,17 @@ public abstract class CharsetEncoder { } /** - * Get the <code>Charset</code> which creates this encoder. + * Gets the <code>Charset</code> which this encoder uses. * - * @return the <code>Charset</code> which creates this encoder + * @return the <code>Charset</code> which this encoder uses. + * @since Android 1.0 */ public final Charset charset() { return cs; } /** - * This is a facade method for encoding operation. + * This is a facade method for the encoding operation. * <p> * This method encodes the remaining character sequence of the given * character buffer into a new byte buffer. This method performs a complete @@ -311,26 +319,27 @@ public abstract class CharsetEncoder { * </p> * * @param in - * the input buffer - * @return a new <code>ByteBuffer</code> containing the the bytes produced - * by this encoding operation. The buffer's limit will be the - * position of last byte in buffer, and the position will be zero + * the input buffer. + * @return a new <code>ByteBuffer</code> containing the bytes produced by + * this encoding operation. The buffer's limit will be the position + * of the last byte in the buffer, and the position will be zero. * @throws IllegalStateException - * if another encoding operation is ongoing + * if another encoding operation is ongoing. * @throws MalformedInputException - * if illegal input character sequence for this charset + * if an illegal input character sequence for this charset is * encountered, and the action for malformed error is * {@link CodingErrorAction#REPORT CodingErrorAction.REPORT} * @throws UnmappableCharacterException - * if legal but unmappable input character sequence for this - * charset encountered, and the action for unmappable character - * error is + * if a legal but unmappable input character sequence for this + * charset is encountered, and the action for unmappable + * character error is * {@link CodingErrorAction#REPORT CodingErrorAction.REPORT}. * Unmappable means the Unicode character sequence at the input * buffer's current position cannot be mapped to a equivalent * byte sequence. * @throws CharacterCodingException - * if other exception happened during the encode operation + * if other exception happened during the encode operation. + * @since Android 1.0 */ public final ByteBuffer encode(CharBuffer in) throws CharacterCodingException { @@ -410,58 +419,59 @@ public abstract class CharsetEncoder { * following rules: * <ul> * <li>A {@link CoderResult#malformedForLength(int) malformed input} result - * indicates that some malformed input error encountered, and the erroneous - * characters start at the input buffer's position and their number can be - * got by result's {@link CoderResult#length() length}. This kind of result - * can be returned only if the malformed action is - * {@link CodingErrorAction#REPORT CodingErrorAction.REPORT}. </li> + * indicates that some malformed input error was encountered, and the + * erroneous characters start at the input buffer's position and their + * number can be got by result's {@link CoderResult#length() length}. This + * kind of result can be returned only if the malformed action is + * {@link CodingErrorAction#REPORT CodingErrorAction.REPORT}.</li> * <li>{@link CoderResult#UNDERFLOW CoderResult.UNDERFLOW} indicates that - * as many characters as possible in the input buffer has been encoded. If + * as many characters as possible in the input buffer have been encoded. If * there is no further input and no characters left in the input buffer then * this task is complete. If this is not the case then the client should * call this method again supplying some more input characters.</li> * <li>{@link CoderResult#OVERFLOW CoderResult.OVERFLOW} indicates that the * output buffer has been filled, while there are still some characters * remaining in the input buffer. This method should be invoked again with a - * non-full output buffer </li> + * non-full output buffer.</li> * <li>A {@link CoderResult#unmappableForLength(int) unmappable character} * result indicates that some unmappable character error was encountered, * and the erroneous characters start at the input buffer's position and * their number can be got by result's {@link CoderResult#length() length}. * This kind of result can be returned only on - * {@link CodingErrorAction#REPORT CodingErrorAction.REPORT}. </li> + * {@link CodingErrorAction#REPORT CodingErrorAction.REPORT}.</li> * </ul> * </p> * <p> - * The <code>endOfInput</code> parameter indicates that if the invoker can + * The <code>endOfInput</code> parameter indicates if the invoker can * provider further input. This parameter is true if and only if the - * characters in current input buffer are all inputs for this encoding - * operation. Note that it is common and won't cause error that the invoker - * sets false and then finds no more input available; while it may cause - * error that the invoker always sets true in several consecutive - * invocations so that any remaining input will be treated as malformed + * characters in the current input buffer are all inputs for this encoding + * operation. Note that it is common and won't cause an error if the invoker + * sets false and then has no more input available, while it may cause an + * error if the invoker always sets true in several consecutive invocations. + * This would make the remaining input to be treated as malformed input. * input. * </p> * <p> - * This method invokes + * This method invokes the * {@link #encodeLoop(CharBuffer, ByteBuffer) encodeLoop} method to - * implement basic encode logic for specific charset. + * implement the basic encode logic for a specific charset. * </p> * * @param in - * the input buffer + * the input buffer. * @param out - * the output buffer + * the output buffer. * @param endOfInput - * true if all the input characters have been provided - * @return a <code>CoderResult</code> instance indicating the result + * true if all the input characters have been provided. + * @return a <code>CoderResult</code> instance indicating the result. * @throws IllegalStateException * if the encoding operation has already started or no more - * input needed in this encoding progress. + * input is needed in this encoding process. * @throws CoderMalfunctionError * If the {@link #encodeLoop(CharBuffer, ByteBuffer) encodeLoop} * method threw an <code>BufferUnderflowException</code> or - * <code>BufferUnderflowException</code> + * <code>BufferUnderflowException</code>. + * @since Android 1.0 */ public final CoderResult encode(CharBuffer in, ByteBuffer out, boolean endOfInput) { @@ -512,68 +522,74 @@ public abstract class CharsetEncoder { } /** - * Encode characters into bytes. This method is called by + * Encodes characters into bytes. This method is called by * {@link #encode(CharBuffer, ByteBuffer, boolean) encode}. - * + * <p> * This method will implement the essential encoding operation, and it won't * stop encoding until either all the input characters are read, the output - * buffer is filled, or some exception encountered. And then it will return - * a <code>CoderResult</code> object indicating the result of current - * encoding operation. The rules to construct the <code>CoderResult</code> - * is same as the {@link #encode(CharBuffer, ByteBuffer, boolean) encode}. - * When exception encountered in the encoding operation, most implementation - * of this method will return a relevant result object to + * buffer is filled, or some exception is encountered. Then it will + * return a <code>CoderResult</code> object indicating the result of the + * current encoding operation. The rule to construct the + * <code>CoderResult</code> is the same as for + * {@link #encode(CharBuffer, ByteBuffer, boolean) encode}. When an + * exception is encountered in the encoding operation, most implementations + * of this method will return a relevant result object to the * {@link #encode(CharBuffer, ByteBuffer, boolean) encode} method, and some * performance optimized implementation may handle the exception and * implement the error action itself. - * + * </p><p> * The buffers are scanned from their current positions, and their positions * will be modified accordingly, while their marks and limits will be * intact. At most {@link CharBuffer#remaining() in.remaining()} characters * will be read, and {@link ByteBuffer#remaining() out.remaining()} bytes * will be written. - * - * Note that some implementation may pre-scan the input buffer and return + * </p><p> + * Note that some implementations may pre-scan the input buffer and return * <code>CoderResult.UNDERFLOW</code> until it receives sufficient input. - * + * <p> * @param in - * the input buffer + * the input buffer. * @param out - * the output buffer - * @return a <code>CoderResult</code> instance indicating the result + * the output buffer. + * @return a <code>CoderResult</code> instance indicating the result. + * @since Android 1.0 */ protected abstract CoderResult encodeLoop(CharBuffer in, ByteBuffer out); /** - * Flush this encoder. - * + * Flushes this encoder. + * <p> * This method will call {@link #implFlush(ByteBuffer) implFlush}. Some * encoders may need to write some bytes to the output buffer when they have * read all input characters, subclasses can overridden * {@link #implFlush(ByteBuffer) implFlush} to perform writing action. - * + * </p> + * <p> * The maximum number of written bytes won't larger than - * {@link ByteBuffer#remaining() out.remaining()}. If some encoder want to - * write more bytes than output buffer's remaining spaces, then + * {@link ByteBuffer#remaining() out.remaining()}. If some encoder wants to + * write more bytes than the output buffer's available remaining space, then * <code>CoderResult.OVERFLOW</code> will be returned, and this method - * must be called again with a byte buffer has more spaces. Otherwise this - * method will return <code>CoderResult.UNDERFLOW</code>, which means one - * encoding process has been completed successfully. - * + * must be called again with a byte buffer that has free space. Otherwise + * this method will return <code>CoderResult.UNDERFLOW</code>, which + * means one encoding process has been completed successfully. + * </p> + * <p> * During the flush, the output buffer's position will be changed * accordingly, while its mark and limit will be intact. + * </p> * * @param out - * the given output buffer + * the given output buffer. * @return <code>CoderResult.UNDERFLOW</code> or - * <code>CoderResult.OVERFLOW</code> + * <code>CoderResult.OVERFLOW</code>. * @throws IllegalStateException * if this encoder hasn't read all input characters during one * encoding process, which means neither after calling * {@link #encode(CharBuffer) encode(CharBuffer)} nor after * calling {@link #encode(CharBuffer, ByteBuffer, boolean) - * encode(CharBuffer, ByteBuffer, boolean)} with true value for - * the last boolean parameter + * encode(CharBuffer, ByteBuffer, boolean)} with {@code true} + * for the last boolean parameter. + * @since Android 1.0 */ public final CoderResult flush(ByteBuffer out) { if (status != END && status != INIT) { @@ -587,64 +603,70 @@ public abstract class CharsetEncoder { } /** - * Flush this encoder. Default implementation does nothing and always return - * <code>CoderResult.UNDERFLOW</code>, and this method can be overridden - * if needed. + * Flushes this encoder. The default implementation does nothing and always + * returns <code>CoderResult.UNDERFLOW</code>; this method can be + * overridden if needed. * * @param out - * the output buffer + * the output buffer. * @return <code>CoderResult.UNDERFLOW</code> or - * <code>CoderResult.OVERFLOW</code> + * <code>CoderResult.OVERFLOW</code>. + * @since Android 1.0 */ protected CoderResult implFlush(ByteBuffer out) { return CoderResult.UNDERFLOW; } /** - * Notify that this encoder's <code>CodingErrorAction</code> specified for - * malformed input error has been changed. Default implementation does - * nothing, and this method can be overridden if needed. + * Notifies that this encoder's <code>CodingErrorAction</code> specified + * for malformed input error has been changed. The default implementation + * does nothing; this method can be overridden if needed. * * @param newAction - * The new action + * the new action. + * @since Android 1.0 */ protected void implOnMalformedInput(CodingErrorAction newAction) { // default implementation is empty } /** - * Notify that this encoder's <code>CodingErrorAction</code> specified for - * unmappable character error has been changed. Default implementation does - * nothing, and this method can be overridden if needed. + * Notifies that this encoder's <code>CodingErrorAction</code> specified + * for unmappable character error has been changed. The default + * implementation does nothing; this method can be overridden if needed. * * @param newAction - * The new action + * the new action. + * @since Android 1.0 */ protected void implOnUnmappableCharacter(CodingErrorAction newAction) { // default implementation is empty } /** - * Notify that this encoder's replacement has been changed. Default - * implementation does nothing, and this method can be overridden if needed. + * Notifies that this encoder's replacement has been changed. The default + * implementation does nothing; this method can be overridden if needed. * * @param newReplacement - * the new replacement string + * the new replacement string. + * @since Android 1.0 */ protected void implReplaceWith(byte[] newReplacement) { // default implementation is empty } /** - * Reset this encoder's charset related state. Default implementation does - * nothing, and this method can be overridden if needed. + * Resets this encoder's charset related state. The default implementation + * does nothing; this method can be overridden if needed. + * + * @since Android 1.0 */ protected void implReset() { // default implementation is empty } /** - * Check if the given argument is legal as this encoder's replacement byte + * Checks if the given argument is legal as this encoder's replacement byte * array. * * The given byte array is legal if and only if it can be decode into @@ -653,9 +675,10 @@ public abstract class CharsetEncoder { * This method can be overridden for performance improvement. * * @param repl - * the given byte array to be checked + * the given byte array to be checked. * @return true if the the given argument is legal as this encoder's * replacement byte array. + * @since Android 1.0 */ public boolean isLegalReplacement(byte[] repl) { if (decoder == null) { @@ -676,39 +699,42 @@ public abstract class CharsetEncoder { } /** - * Gets this encoder's <code>CodingErrorAction</code> when malformed input - * occurred during encoding process. + * Gets this encoder's <code>CodingErrorAction</code> when a malformed + * input error occurred during the encoding process. * - * @return this encoder's <code>CodingErrorAction</code> when malformed - * input occurred during encoding process. + * @return this encoder's <code>CodingErrorAction</code> when a malformed + * input error occurred during the encoding process. + * @since Android 1.0 */ public CodingErrorAction malformedInputAction() { return malformAction; } /** - * Get the maximum number of bytes which can be created by this encoder for - * one input character, must be positive + * Gets the maximum number of bytes which can be created by this encoder for + * one input character, must be positive. * * @return the maximum number of bytes which can be created by this encoder - * for one input character, must be positive + * for one input character, must be positive. + * @since Android 1.0 */ public final float maxBytesPerChar() { return maxBytes; } /** - * Set this encoder's action on malformed input error. + * Sets this encoder's action on malformed input error. * * This method will call the * {@link #implOnMalformedInput(CodingErrorAction) implOnMalformedInput} * method with the given new action as argument. * * @param newAction - * the new action on malformed input error - * @return this encoder + * the new action on malformed input error. + * @return this encoder. * @throws IllegalArgumentException - * if the given newAction is null + * if the given newAction is null. + * @since Android 1.0 */ public final CharsetEncoder onMalformedInput(CodingErrorAction newAction) { if (null == newAction) { @@ -721,17 +747,18 @@ public abstract class CharsetEncoder { } /** - * Set this encoder's action on unmappable character error. + * Sets this encoder's action on unmappable character error. * * This method will call the * {@link #implOnUnmappableCharacter(CodingErrorAction) implOnUnmappableCharacter} * method with the given new action as argument. * * @param newAction - * the new action on unmappable character error - * @return this encoder + * the new action on unmappable character error. + * @return this encoder. * @throws IllegalArgumentException - * if the given newAction is null + * if the given newAction is null. + * @since Android 1.0 */ public final CharsetEncoder onUnmappableCharacter( CodingErrorAction newAction) { @@ -745,33 +772,33 @@ public abstract class CharsetEncoder { } /** - * Get the replacement byte array, which is never null or empty, and it is - * legal + * Gets the replacement byte array, which is never null or empty. * - * @return the replacement byte array, cannot be null or empty, and it is - * legal + * @return the replacement byte array, cannot be null or empty. + * @since Android 1.0 */ public final byte[] replacement() { return replace; } /** - * Set new replacement value. + * Sets the new replacement value. * * This method first checks the given replacement's validity, then changes - * the replacement value, and at last calls + * the replacement value and finally calls the * {@link #implReplaceWith(byte[]) implReplaceWith} method with the given * new replacement as argument. * * @param replacement * the replacement byte array, cannot be null or empty, its - * length cannot larger than <code>maxBytesPerChar</code>, and - * must be legal replacement, which can be justified by - * <code>isLegalReplacement(byte[] repl)</code> - * @return this encoder + * length cannot be larger than <code>maxBytesPerChar</code>, + * and it must be legal replacement, which can be justified by + * calling <code>isLegalReplacement(byte[] repl)</code>. + * @return this encoder. * @throws IllegalArgumentException * if the given replacement cannot satisfy the requirement - * mentioned above + * mentioned above. + * @since Android 1.0 */ public final CharsetEncoder replaceWith(byte[] replacement) { if (null == replacement || 0 == replacement.length @@ -786,11 +813,12 @@ public abstract class CharsetEncoder { } /** - * Reset this encoder. This method will reset internal status, and then call - * <code>implReset()</code> to reset any status related to specific - * charset. + * Resets this encoder. This method will reset the internal status and then + * calla <code>implReset()</code> to reset any status related to the + * specific charset. * - * @return this encoder + * @return this encoder. + * @since Android 1.0 */ public final CharsetEncoder reset() { status = INIT; @@ -804,6 +832,7 @@ public abstract class CharsetEncoder { * * @return this encoder's <code>CodingErrorAction</code> when unmappable * character occurred during encoding process. + * @since Android 1.0 */ public CodingErrorAction unmappableCharacterAction() { return unmapAction; diff --git a/nio_char/src/main/java/java/nio/charset/CoderMalfunctionError.java b/nio_char/src/main/java/java/nio/charset/CoderMalfunctionError.java index c2400cb..2fc2ae8 100644 --- a/nio_char/src/main/java/java/nio/charset/CoderMalfunctionError.java +++ b/nio_char/src/main/java/java/nio/charset/CoderMalfunctionError.java @@ -18,21 +18,25 @@ package java.nio.charset; /** - * Errors thrown when the encoder/decoder is malfunctioning. + * A {@code CoderMalfunctionError} is thrown when the encoder/decoder is + * malfunctioning. + * + * @since Android 1.0 */ public class CoderMalfunctionError extends Error { /* - * This constant is used during deserialization to check the J2SE version + * This constant is used during deserialization to check the version * which created the serialized object. */ private static final long serialVersionUID = -1151412348057794301L; /** - * Constructs an instance of this error. + * Constructs a new {@code CoderMalfunctionError}. * * @param ex - * the original exception thrown by the encoder/decoder + * the original exception thrown by the encoder/decoder. + * @since Android 1.0 */ public CoderMalfunctionError(Exception ex) { super(ex); diff --git a/nio_char/src/main/java/java/nio/charset/CoderResult.java b/nio_char/src/main/java/java/nio/charset/CoderResult.java index c222394..9d47c9f 100644 --- a/nio_char/src/main/java/java/nio/charset/CoderResult.java +++ b/nio_char/src/main/java/java/nio/charset/CoderResult.java @@ -26,21 +26,22 @@ import org.apache.harmony.niochar.internal.nls.Messages; * Used to indicate the result of encoding/decoding. There are four types of * results: * <ol> - * <li>UNDERFLOW indicates all input has been processed, or more input is + * <li>UNDERFLOW indicates that all input has been processed but more input is * required. It is represented by the unique object * <code>CoderResult.UNDERFLOW</code>. - * <li>OVERFLOW indicates insufficient output buffer. It is represented by the - * unique object <code>CoderResult.OVERFLOW</code>. - * <li>A malformed-input error indicates an unrecognizable sequence of input - * units has been encountered. Get an instance of this type of result by calling - * <code>CoderResult.malformedForLength(int)</code> with the length of the - * malformed-input. - * <li>An unmappable-character error indicates a sequence of input units can - * not be mapped to the output charset. Get an instance of this type of result - * by calling <code>CoderResult.unmappableForLength(int)</code> with the input - * sequence size indicating the identity of the unmappable character. + * <li>OVERFLOW indicates an insufficient output buffer size. It is represented + * by the unique object <code>CoderResult.OVERFLOW</code>. + * <li>A malformed-input error indicates that an unrecognizable sequence of + * input units has been encountered. Get an instance of this type of result by + * calling <code>CoderResult.malformedForLength(int)</code> with the length of + * the malformed-input. + * <li>An unmappable-character error indicates that a sequence of input units + * can not be mapped to the output charset. Get an instance of this type of + * result by calling <code>CoderResult.unmappableForLength(int)</code> with + * the input sequence size indicating the identity of the unmappable character. * </ol> * + * @since Android 1.0 */ public class CoderResult { @@ -59,13 +60,17 @@ public class CoderResult { /** * Result object indicating that there is insufficient data in the * encoding/decoding buffer or that additional data is required. + * + * @since Android 1.0 */ public static final CoderResult UNDERFLOW = new CoderResult(TYPE_UNDERFLOW, 0); /** - * Result object used to signify that the out buffer does not have enough - * space available in it to store the result of the encoding/decoding. + * Result object used to indicate that the output buffer does not have + * enough space available to store the result of the encoding/decoding. + * + * @since Android 1.0 */ public static final CoderResult OVERFLOW = new CoderResult(TYPE_OVERFLOW, 0); @@ -81,14 +86,14 @@ public class CoderResult { */ private static WeakHashMap<Integer, CoderResult> _unmappableErrors = new WeakHashMap<Integer, CoderResult>(); - // the type this result + // the type of this result private final int type; // the length of the erroneous input private final int length; /** - * Construct a <code>CoderResult</code> object with its text description. + * Constructs a <code>CoderResult</code> object with its text description. * * @param type * the type of this result @@ -106,11 +111,12 @@ public class CoderResult { * error. * * @param length - * the length of the malformed-input + * the length of the malformed-input. * @return a <code>CoderResult</code> object indicating a malformed-input - * error + * error. * @throws IllegalArgumentException - * If <code>length</code> is non-positive. + * if <code>length</code> is non-positive. + * @since Android 1.0 */ public static synchronized CoderResult malformedForLength(int length) throws IllegalArgumentException { @@ -136,11 +142,12 @@ public class CoderResult { * * @param length * the length of the input unit sequence denoting the unmappable - * character + * character. * @return a <code>CoderResult</code> object indicating an unmappable - * character error + * character error. * @throws IllegalArgumentException - * If <code>length</code> is non-positive. + * if <code>length</code> is non-positive. + * @since Android 1.0 */ public static synchronized CoderResult unmappableForLength(int length) throws IllegalArgumentException { @@ -163,7 +170,8 @@ public class CoderResult { /** * Returns true if this result is an underflow condition. * - * @return true if an underflow, otherwise false + * @return true if an underflow, otherwise false. + * @since Android 1.0 */ public boolean isUnderflow() { return this.type == TYPE_UNDERFLOW; @@ -173,8 +181,9 @@ public class CoderResult { * Returns true if this result represents a malformed-input error or an * unmappable-character error. * - * @return true if a malformed-input error or an unmappable-character error, - * otherwise false + * @return true if this is a malformed-input error or an + * unmappable-character error, otherwise false. + * @since Android 1.0 */ public boolean isError() { return this.type == TYPE_MALFORMED_INPUT @@ -184,7 +193,8 @@ public class CoderResult { /** * Returns true if this result represents a malformed-input error. * - * @return true if a malformed-input error, otherwise false + * @return true if this is a malformed-input error, otherwise false. + * @since Android 1.0 */ public boolean isMalformed() { return this.type == TYPE_MALFORMED_INPUT; @@ -193,7 +203,8 @@ public class CoderResult { /** * Returns true if this result is an overflow condition. * - * @return true if an overflow, otherwise false + * @return true if this is an overflow, otherwise false. + * @since Android 1.0 */ public boolean isOverflow() { return this.type == TYPE_OVERFLOW; @@ -202,7 +213,8 @@ public class CoderResult { /** * Returns true if this result represents an unmappable-character error. * - * @return true if an unmappable-character error, otherwise false + * @return true if this is an unmappable-character error, otherwise false. + * @since Android 1.0 */ public boolean isUnmappable() { return this.type == TYPE_UNMAPPABLE_CHAR; @@ -212,9 +224,10 @@ public class CoderResult { * Gets the length of the erroneous input. The length is only meaningful to * a malformed-input error or an unmappble character error. * - * @return the length, as an integer, of this object's erroneous input + * @return the length, as an integer, of this object's erroneous input. * @throws UnsupportedOperationException - * If this result is an overflow or underflow. + * if this result is an overflow or underflow. + * @since Android 1.0 */ public int length() throws UnsupportedOperationException { if (this.type == TYPE_MALFORMED_INPUT @@ -231,15 +244,16 @@ public class CoderResult { * Throws an exception corresponding to this coder result. * * @throws BufferUnderflowException - * If an underflow. + * in case this is an underflow. * @throws BufferOverflowException - * If an overflow. + * in case this is an overflow. * @throws UnmappableCharacterException - * If an unmappable-character error. + * in case this is an unmappable-character error. * @throws MalformedInputException - * If a malformed-input error. + * in case this is a malformed-input error. * @throws CharacterCodingException - * The default exception. + * the default exception. + * @since Android 1.0 */ public void throwException() throws BufferUnderflowException, BufferOverflowException, UnmappableCharacterException, @@ -267,7 +281,8 @@ public class CoderResult { /** * Returns a text description of this result. * - * @return a text description of this result + * @return a text description of this result. + * @since Android 1.0 */ public String toString() { String dsc = null; diff --git a/nio_char/src/main/java/java/nio/charset/CodingErrorAction.java b/nio_char/src/main/java/java/nio/charset/CodingErrorAction.java index e258c71..d949c81 100644 --- a/nio_char/src/main/java/java/nio/charset/CodingErrorAction.java +++ b/nio_char/src/main/java/java/nio/charset/CodingErrorAction.java @@ -18,27 +18,36 @@ package java.nio.charset; /** * Used to indicate what kind of actions to take in case of encoding/decoding - * errors. Currently three actions are defined, namely, IGNORE, REPLACE and - * REPORT. + * errors. Currently three actions are defined: {@code IGNORE}, {@code REPLACE} + * and {@code REPORT}. + * + * @since Android 1.0 */ public class CodingErrorAction { /** - * Indicating the action to ignore any errors. + * Denotes the action to ignore any errors. + * + * @since Android 1.0 */ public static final CodingErrorAction IGNORE = new CodingErrorAction( "IGNORE"); //$NON-NLS-1$ /** - * Indicating the action to fill in the output with a replacement character + * Denotes the action to fill in the output with a replacement character * when malformed input or an unmappable character is encountered. + * + * @since Android 1.0 */ public static final CodingErrorAction REPLACE = new CodingErrorAction( "REPLACE"); //$NON-NLS-1$ /** - * Indicating the action to report the encountered error in an appropriate - * manner, for example, throw an exception or return an informative result. + * Denotes the action to report the encountered error in an appropriate + * manner, for example to throw an exception or return an informative + * result. + * + * @since Android 1.0 */ public static final CodingErrorAction REPORT = new CodingErrorAction( "REPORT"); //$NON-NLS-1$ @@ -54,9 +63,10 @@ public class CodingErrorAction { } /** - * Returns a text description of this action indication.. + * Returns a text description of this action indication. * * @return a text description of this action indication. + * @since Android 1.0 */ public String toString() { return "Action: " + this.action; //$NON-NLS-1$ diff --git a/nio_char/src/main/java/java/nio/charset/IllegalCharsetNameException.java b/nio_char/src/main/java/java/nio/charset/IllegalCharsetNameException.java index fae1269..36ff3ad 100644 --- a/nio_char/src/main/java/java/nio/charset/IllegalCharsetNameException.java +++ b/nio_char/src/main/java/java/nio/charset/IllegalCharsetNameException.java @@ -20,12 +20,15 @@ package java.nio.charset; import org.apache.harmony.niochar.internal.nls.Messages; /** - * Thrown when an illegal charset name is encountered. + * An {@code IllegalCharsetNameException} is thrown when an illegal charset name + * is encountered. + * + * @since Android 1.0 */ public class IllegalCharsetNameException extends IllegalArgumentException { /* - * This constant is used during deserialization to check the J2SE version + * This constant is used during deserialization to check the version * which created the serialized object. */ private static final long serialVersionUID = 1457525358470002989L; @@ -34,10 +37,12 @@ public class IllegalCharsetNameException extends IllegalArgumentException { private String charsetName; /** - * Constructs an instance of this exception with the supplied charset name. + * Constructs a new {@code IllegalCharsetNameException} with the supplied + * charset name. * * @param charset - * the encountered illegal charset name + * the encountered illegal charset name. + * @since Android 1.0 */ public IllegalCharsetNameException(String charset) { // niochar.0F=The illegal charset name is "{0}". @@ -48,7 +53,8 @@ public class IllegalCharsetNameException extends IllegalArgumentException { /** * Gets the encountered illegal charset name. * - * @return the encountered illegal charset name + * @return the encountered illegal charset name. + * @since Android 1.0 */ public String getCharsetName() { return this.charsetName; diff --git a/nio_char/src/main/java/java/nio/charset/MalformedInputException.java b/nio_char/src/main/java/java/nio/charset/MalformedInputException.java index 17b0005..9fa0aa2 100644 --- a/nio_char/src/main/java/java/nio/charset/MalformedInputException.java +++ b/nio_char/src/main/java/java/nio/charset/MalformedInputException.java @@ -20,13 +20,15 @@ package java.nio.charset; import org.apache.harmony.niochar.internal.nls.Messages; /** - * Thrown when a malformed input is encountered, for example, a byte sequence is - * illegal for the given charset. + * A {@code MalformedInputException} is thrown when a malformed input is + * encountered, for example if a byte sequence is illegal for the given charset. + * + * @since Android 1.0 */ public class MalformedInputException extends CharacterCodingException { /* - * This constant is used during deserialization to check the J2SE version + * This constant is used during deserialization to check the version * which created the serialized object. */ private static final long serialVersionUID = -3438823399834806194L; @@ -35,10 +37,11 @@ public class MalformedInputException extends CharacterCodingException { private int inputLength; /** - * Constructs an instance of this exception. + * Constructs a new {@code MalformedInputException}. * * @param length - * the length of the malformed input + * the length of the malformed input. + * @since Android 1.0 */ public MalformedInputException(int length) { this.inputLength = length; @@ -47,7 +50,8 @@ public class MalformedInputException extends CharacterCodingException { /** * Gets the length of the malformed input. * - * @return the length of the malformed input + * @return the length of the malformed input. + * @since Android 1.0 */ public int getInputLength() { return this.inputLength; @@ -56,7 +60,8 @@ public class MalformedInputException extends CharacterCodingException { /** * Gets a message describing this exception. * - * @return a message describing this exception + * @return a message describing this exception. + * @since Android 1.0 */ public String getMessage() { // niochar.05=Malformed input length is {0}. diff --git a/nio_char/src/main/java/java/nio/charset/UnmappableCharacterException.java b/nio_char/src/main/java/java/nio/charset/UnmappableCharacterException.java index 1c66c52..7cc56e2 100644 --- a/nio_char/src/main/java/java/nio/charset/UnmappableCharacterException.java +++ b/nio_char/src/main/java/java/nio/charset/UnmappableCharacterException.java @@ -20,12 +20,15 @@ package java.nio.charset; import org.apache.harmony.niochar.internal.nls.Messages; /** - * Thrown when an unmappable character for the given charset is encountered. + * An {@code UnmappableCharacterException} is thrown when an unmappable + * character for the given charset is encountered. + * + * @since Android 1.0 */ public class UnmappableCharacterException extends CharacterCodingException { /* - * This constant is used during deserialization to check the J2SE version + * This constant is used during deserialization to check the version * which created the serialized object. */ private static final long serialVersionUID = -7026962371537706123L; @@ -34,10 +37,11 @@ public class UnmappableCharacterException extends CharacterCodingException { private int inputLength; /** - * Constructs an instance of this exception. + * Constructs a new {@code UnmappableCharacterException}. * * @param length - * the length of the unmappable character + * the length of the unmappable character. + * @since Android 1.0 */ public UnmappableCharacterException(int length) { this.inputLength = length; @@ -46,7 +50,8 @@ public class UnmappableCharacterException extends CharacterCodingException { /** * Gets the length of the unmappable character. * - * @return the length of the unmappable character + * @return the length of the unmappable character. + * @since Android 1.0 */ public int getInputLength() { return this.inputLength; @@ -55,7 +60,8 @@ public class UnmappableCharacterException extends CharacterCodingException { /** * Gets a message describing this exception. * - * @return a message describing this exception + * @return a message describing this exception. + * @since Android 1.0 */ public String getMessage() { // niochar.0A=The unmappable character length is {0}. diff --git a/nio_char/src/main/java/java/nio/charset/UnsupportedCharsetException.java b/nio_char/src/main/java/java/nio/charset/UnsupportedCharsetException.java index 1b55397..45dbf3d 100644 --- a/nio_char/src/main/java/java/nio/charset/UnsupportedCharsetException.java +++ b/nio_char/src/main/java/java/nio/charset/UnsupportedCharsetException.java @@ -20,12 +20,15 @@ package java.nio.charset; import org.apache.harmony.niochar.internal.nls.Messages; /** - * Thrown when an unsupported charset name is encountered. + * An {@code UnsupportedCharsetException} is thrown when an unsupported charset + * name is encountered. + * + * @since Android 1.0 */ public class UnsupportedCharsetException extends IllegalArgumentException { /* - * This constant is used during deserialization to check the J2SE version + * This constant is used during deserialization to check the version * which created the serialized object. */ private static final long serialVersionUID = 1490765524727386367L; @@ -34,10 +37,11 @@ public class UnsupportedCharsetException extends IllegalArgumentException { private String charsetName; /** - * Constructs an instance of this exception with the supplied charset name. + * Constructs a new {@code UnsupportedCharsetException} with the supplied charset name. * * @param charset - * the encountered unsupported charset name + * the encountered unsupported charset name. + * @since Android 1.0 */ public UnsupportedCharsetException(String charset) { // niochar.04=The unsupported charset name is "{0}". @@ -48,7 +52,8 @@ public class UnsupportedCharsetException extends IllegalArgumentException { /** * Gets the encountered unsupported charset name. * - * @return the encountered unsupported charset name + * @return the encountered unsupported charset name. + * @since Android 1.0 */ public String getCharsetName() { return this.charsetName; diff --git a/nio_char/src/main/java/java/nio/charset/package.html b/nio_char/src/main/java/java/nio/charset/package.html index 104fd50..175fb71 100644 --- a/nio_char/src/main/java/java/nio/charset/package.html +++ b/nio_char/src/main/java/java/nio/charset/package.html @@ -1,7 +1,7 @@ <html> <body> <p> - This package allows translating between bytes and different + This package provides translation services between bytes and different character sets. </p> <p> @@ -10,5 +10,6 @@ de-/encoder pair that can be used to translate a byte stream. With the service provider package it is possible to use your own charsets. </p> + @since Android 1.0 </body> </html> diff --git a/nio_char/src/main/java/java/nio/charset/spi/CharsetProvider.java b/nio_char/src/main/java/java/nio/charset/spi/CharsetProvider.java index 8a470d7..6d5c66f 100644 --- a/nio_char/src/main/java/java/nio/charset/spi/CharsetProvider.java +++ b/nio_char/src/main/java/java/nio/charset/spi/CharsetProvider.java @@ -21,6 +21,8 @@ import java.util.Iterator; /** * The service provider class for character sets. + * + * @since Android 1.0 */ public abstract class CharsetProvider { @@ -34,6 +36,7 @@ public abstract class CharsetProvider { * @throws SecurityException * if there is a security manager installed that does not permit * the runtime permission labeled "charsetProvider". + * @since Android 1.0 */ protected CharsetProvider() { SecurityManager securityManager = System.getSecurityManager(); @@ -45,6 +48,7 @@ public abstract class CharsetProvider { * Returns an iterator over all the available charsets. * * @return the iterator. + * @since Android 1.0 */ public abstract Iterator<Charset> charsets(); @@ -52,10 +56,12 @@ public abstract class CharsetProvider { * Returns the named charset. * <p> * If the charset is unavailable the method returns <code>null</code>. + * </p> * * @param charsetName * the canonical or alias name of a character set. * @return the charset, or <code>null</code> if unavailable. + * @since Android 1.0 */ public abstract Charset charsetForName(String charsetName); } diff --git a/nio_char/src/main/java/java/nio/charset/spi/package.html b/nio_char/src/main/java/java/nio/charset/spi/package.html index a68c6d3..f7d9d2b 100644 --- a/nio_char/src/main/java/java/nio/charset/spi/package.html +++ b/nio_char/src/main/java/java/nio/charset/spi/package.html @@ -1,7 +1,8 @@ <html> <body> <p> - Service-provider classe for nio charset. + Service-provider class for nio charset. </p> + @since Android 1.0 </body> </html> diff --git a/nio_char/src/main/java/org/apache/harmony/niochar/internal/nls/Messages.java b/nio_char/src/main/java/org/apache/harmony/niochar/internal/nls/Messages.java index 3368864..f2fb652 100644 --- a/nio_char/src/main/java/org/apache/harmony/niochar/internal/nls/Messages.java +++ b/nio_char/src/main/java/org/apache/harmony/niochar/internal/nls/Messages.java @@ -21,9 +21,22 @@ * if this tool runs again. Better make changes in the template file. */ +// BEGIN android-note +// Redundant code has been removed and is now called from MsgHelp. +// END android-note + package org.apache.harmony.niochar.internal.nls; + +import java.security.AccessController; +import java.security.PrivilegedAction; +import java.util.Locale; +import java.util.MissingResourceException; +import java.util.ResourceBundle; + +// BEGIN android-changed import org.apache.harmony.luni.util.MsgHelp; +// END android-changed /** * This class retrieves strings from a resource bundle and returns them, @@ -40,9 +53,11 @@ import org.apache.harmony.luni.util.MsgHelp; * */ public class Messages { - + + // BEGIN android-changed private static final String sResource = "org.apache.harmony.niochar.internal.nls.messages"; //$NON-NLS-1$ + // END android-changed /** * Retrieves a message which has no arguments. @@ -52,7 +67,9 @@ public class Messages { * @return String the message for that key in the system message bundle. */ static public String getString(String msg) { + // BEGIN android-changed return MsgHelp.getString(sResource, msg); + // END android-changed } /** @@ -119,7 +136,13 @@ public class Messages { * @return String the message for that key in the system message bundle. */ static public String getString(String msg, Object[] args) { + // BEGIN android-changed return MsgHelp.getString(sResource, msg, args); + // END android-changed } + + // BEGIN android-note + // Duplicate code was dropped in favor of using MsgHelp. + // END android-note } diff --git a/nio_char/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/ASCIICharsetEncoderTest.java b/nio_char/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/ASCIICharsetEncoderTest.java index 01385f2..f704e3b 100644 --- a/nio_char/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/ASCIICharsetEncoderTest.java +++ b/nio_char/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/ASCIICharsetEncoderTest.java @@ -16,6 +16,11 @@ package org.apache.harmony.nio_char.tests.java.nio.charset; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestLevel; + import java.nio.ByteBuffer; import java.nio.CharBuffer; import java.nio.charset.CharacterCodingException; @@ -27,7 +32,7 @@ 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 @@ -46,6 +51,15 @@ public class ASCIICharsetEncoderTest extends TestCase { protected void tearDown() throws Exception { } +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "IllegalStateException checking missed.", + targets = { + @TestTarget( + methodName = "canEncode", + methodArgs = {java.lang.CharSequence.class} + ) + }) public void testCanEncodeCharSequence() { // normal case for ascCS assertTrue(encoder.canEncode("\u0077")); @@ -58,21 +72,66 @@ public class ASCIICharsetEncoderTest extends TestCase { assertTrue(encoder.canEncode("")); } +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "IllegalStateException checking missed.", + targets = { + @TestTarget( + methodName = "canEncode", + methodArgs = {java.lang.CharSequence.class} + ),@TestTarget( + methodName = "canEncode", + methodArgs = {char.class} + ) + }) public void testCanEncodeSurrogate () { assertFalse(encoder.canEncode('\ud800')); assertFalse(encoder.canEncode("\udc00")); } +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "IllegalStateException checking missed.", + targets = { + @TestTarget( + methodName = "canEncode", + methodArgs = {char.class} + ) + }) public void testCanEncodechar() throws CharacterCodingException { assertTrue(encoder.canEncode('\u0077')); assertFalse(encoder.canEncode('\uc2a3')); } +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "averageBytesPerChar", + methodArgs = {} + ),@TestTarget( + methodName = "maxBytesPerChar", + methodArgs = {} + ) + }) public void testSpecificDefaultValue() { assertEquals(1.0, encoder.averageBytesPerChar(), 0.0); assertEquals(1.0, encoder.maxBytesPerChar(), 0.0); } +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "Exceptions checking missed.", + targets = { + @TestTarget( + methodName = "encode", + methodArgs = {java.nio.CharBuffer.class, java.nio.ByteBuffer.class, boolean.class} + ),@TestTarget( + methodName = "encode", + methodArgs = {java.nio.CharBuffer.class} + ) + }) public void testMultiStepEncode() throws CharacterCodingException { encoder.onMalformedInput(CodingErrorAction.REPORT); encoder.onUnmappableCharacter(CodingErrorAction.REPORT); @@ -94,6 +153,15 @@ public class ASCIICharsetEncoderTest extends TestCase { .isMalformed()); } +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "encode", + methodArgs = {java.nio.CharBuffer.class} + ) + }) public void testEncodeMapping() throws CharacterCodingException { encoder.reset(); @@ -129,6 +197,21 @@ public class ASCIICharsetEncoderTest extends TestCase { } } +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "Checks functionality. Exceptions checking missed.", + targets = { + @TestTarget( + methodName = "encode", + methodArgs = {java.nio.CharBuffer.class, java.nio.ByteBuffer.class, boolean.class} + ), @TestTarget( + methodName = "flush", + methodArgs = {java.nio.ByteBuffer.class} + ), @TestTarget( + methodName = "reset", + methodArgs = {} + ) + }) public void testInternalState() { CharBuffer in = CharBuffer.wrap("A"); ByteBuffer out = ByteBuffer.allocate(0x10); @@ -142,6 +225,21 @@ public class ASCIICharsetEncoderTest extends TestCase { } //reset could be called at any time +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "Checks functionality. Exceptions checking missed.", + targets = { + @TestTarget( + methodName = "reset", + methodArgs = {} + ), @TestTarget( + methodName = "encode", + methodArgs = {java.nio.CharBuffer.class, java.nio.ByteBuffer.class, boolean.class} + ), @TestTarget( + methodName = "flush", + methodArgs = {java.nio.ByteBuffer.class} + ) + }) public void testInternalState_Reset() { CharsetEncoder newEncoder = cs.newEncoder(); //Init - > reset @@ -175,6 +273,15 @@ public class ASCIICharsetEncoderTest extends TestCase { } } +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "CoderMalfunctionError checking missed.", + targets = { + @TestTarget( + methodName = "encode", + methodArgs = {java.nio.CharBuffer.class, java.nio.ByteBuffer.class, boolean.class} + ) + }) public void testInternalState_Encoding() { CharsetEncoder newEncoder = cs.newEncoder(); //Init - > encoding @@ -232,6 +339,15 @@ public class ASCIICharsetEncoderTest extends TestCase { } } +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "CoderMalfunctionError checking missed.", + targets = { + @TestTarget( + methodName = "encode", + methodArgs = {java.nio.CharBuffer.class, java.nio.ByteBuffer.class, boolean.class} + ) + }) public void testInternalState_Encoding_END() { CharsetEncoder newEncoder = cs.newEncoder(); @@ -287,6 +403,15 @@ public class ASCIICharsetEncoderTest extends TestCase { } } +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "CoderMalfunctionError checking missed.", + targets = { + @TestTarget( + methodName = "encode", + methodArgs = {java.nio.CharBuffer.class, java.nio.ByteBuffer.class, boolean.class} + ) + }) public void testInternalState_Flushed() { CharsetEncoder newEncoder = cs.newEncoder(); @@ -346,6 +471,21 @@ public class ASCIICharsetEncoderTest extends TestCase { } } +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "Functional test.", + targets = { + @TestTarget( + methodName = "encode", + methodArgs = {java.nio.CharBuffer.class} + ), @TestTarget( + methodName = "flush", + methodArgs = {java.nio.ByteBuffer.class} + ), @TestTarget( + methodName = "reset", + methodArgs = {} + ) + }) public void testInternalState_Encode() throws CharacterCodingException { CharsetEncoder newEncoder = cs.newEncoder(); //Init - > encode @@ -393,6 +533,24 @@ public class ASCIICharsetEncoderTest extends TestCase { } } +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "CoderMalfunctionError checking missed.", + targets = { + @TestTarget( + methodName = "encode", + methodArgs = {java.nio.CharBuffer.class} + ), @TestTarget( + methodName = "encode", + methodArgs = {java.nio.CharBuffer.class, java.nio.ByteBuffer.class, boolean.class} + ), @TestTarget( + methodName = "flush", + methodArgs = {java.nio.ByteBuffer.class} + ), @TestTarget( + methodName = "reset", + methodArgs = {} + ) + }) public void testInternalState_from_Encode() throws CharacterCodingException { CharsetEncoder newEncoder = cs.newEncoder(); diff --git a/nio_char/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/AllTests.java b/nio_char/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/AllTests.java index 8dd485c..c8f063e 100644 --- a/nio_char/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/AllTests.java +++ b/nio_char/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/AllTests.java @@ -29,6 +29,7 @@ public class AllTests { 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); diff --git a/nio_char/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/CharacterCodingExceptionTest.java b/nio_char/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/CharacterCodingExceptionTest.java index f1bab63..1fbeace 100644 --- a/nio_char/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/CharacterCodingExceptionTest.java +++ b/nio_char/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/CharacterCodingExceptionTest.java @@ -16,6 +16,11 @@ package org.apache.harmony.nio_char.tests.java.nio.charset; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestLevel; + import java.io.IOException; import java.nio.charset.CharacterCodingException; @@ -23,11 +28,21 @@ import junit.framework.TestCase; import org.apache.harmony.testframework.serialization.SerializationTest; +@TestTargetClass(CharacterCodingException.class) /** * Test CharacterCodingException */ public class CharacterCodingExceptionTest extends TestCase { +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "CharacterCodingException", + methodArgs = {} + ) + }) public void testConstructor() { CharacterCodingException ex = new CharacterCodingException(); assertTrue(ex instanceof IOException); @@ -38,6 +53,15 @@ public class CharacterCodingExceptionTest extends TestCase { /** * @tests serialization/deserialization compatibility. */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "Verifies serialization.", + targets = { + @TestTarget( + methodName = "!SerializationSelf", + methodArgs = {} + ) + }) public void testSerializationSelf() throws Exception { SerializationTest.verifySelf(new CharacterCodingException()); @@ -46,6 +70,15 @@ public class CharacterCodingExceptionTest extends TestCase { /** * @tests serialization/deserialization compatibility with RI. */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "Verifies serialization.", + targets = { + @TestTarget( + methodName = "!SerializationGolden", + methodArgs = {} + ) + }) public void testSerializationCompatibility() throws Exception { SerializationTest.verifyGolden(this, new CharacterCodingException()); diff --git a/nio_char/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/CharsetDecoderTest.java b/nio_char/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/CharsetDecoderTest.java index 8617669..ec89ed5 100644 --- a/nio_char/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/CharsetDecoderTest.java +++ b/nio_char/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/CharsetDecoderTest.java @@ -16,6 +16,11 @@ package org.apache.harmony.nio_char.tests.java.nio.charset; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestLevel; + import java.nio.BufferOverflowException; import java.nio.ByteBuffer; import java.nio.CharBuffer; @@ -29,13 +34,22 @@ import java.nio.charset.CodingErrorAction; import java.nio.charset.MalformedInputException; import junit.framework.TestCase; - +@TestTargetClass(CharsetDecoder.class) public class CharsetDecoderTest extends TestCase { /** * @tests java.nio.charset.CharsetDecoder.CharsetDecoder(Charset, float, * float) */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "Checks IllegalArgumentException.", + targets = { + @TestTarget( + methodName = "CharsetDecoder", + methodArgs = {java.nio.charset.Charset.class, float.class, float.class} + ) + }) public void test_ConstructorLjava_nio_charset_CharsetFF() { // Regression for HARMONY-142 try { @@ -64,6 +78,15 @@ public class CharsetDecoderTest extends TestCase { /** * @tests java.nio.charset.CharsetDecoder#decode(java.nio.ByteBuffer) */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "Regression test.", + targets = { + @TestTarget( + methodName = "decode", + methodArgs = {java.nio.ByteBuffer.class} + ) + }) public void test_decode() throws CharacterCodingException { // Regression for HARMONY-33 // ByteBuffer bb = ByteBuffer.allocate(1); @@ -101,6 +124,15 @@ public class CharsetDecoderTest extends TestCase { /* * Test malfunction decode(ByteBuffer) */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "Regression test. Checks CoderMalfunctionError", + targets = { + @TestTarget( + methodName = "decode", + methodArgs = {java.nio.ByteBuffer.class} + ) + }) public void test_decodeLjava_nio_ByteBuffer() throws Exception { MockMalfunctionCharset cs1 = new MockMalfunctionCharset( "Harmony-124-1", null); //$NON-NLS-1$ @@ -176,6 +208,21 @@ public class CharsetDecoderTest extends TestCase { /* * Test the method decode(ByteBuffer) . */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "Functional test.", + targets = { + @TestTarget( + methodName = "decode", + methodArgs = {java.nio.ByteBuffer.class, java.nio.CharBuffer.class, boolean.class} + ),@TestTarget( + methodName = "implOnMalformedInput", + methodArgs = {java.nio.charset.CodingErrorAction.class} + ),@TestTarget( + methodName = "replaceWith", + methodArgs = {java.lang.String.class} + ) + }) public void testDecodeLjava_nio_ByteBuffer_ReplaceOverflow() throws Exception { String replaceString = "a"; diff --git a/nio_char/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/CharsetEncoderTest.java b/nio_char/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/CharsetEncoderTest.java index fce2a1a..104b993 100644 --- a/nio_char/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/CharsetEncoderTest.java +++ b/nio_char/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/CharsetEncoderTest.java @@ -16,6 +16,11 @@ package org.apache.harmony.nio_char.tests.java.nio.charset; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestLevel; + import java.nio.BufferOverflowException; import java.nio.ByteBuffer; import java.nio.CharBuffer; @@ -26,13 +31,25 @@ 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) */ +@TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Checks IllegalArgumentException", + targets = { + @TestTarget( + methodName = "CharsetEncoder", + methodArgs = {java.nio.charset.Charset.class, float.class, float.class} + ), @TestTarget( + methodName = "CharsetEncoder", + methodArgs = {java.nio.charset.Charset.class, float.class, float.class, byte[].class} + ) + }) public void test_ConstructorLjava_nio_charset_CharsetFF() { // Regression for HARMONY-141 try { @@ -57,6 +74,15 @@ public class CharsetEncoderTest extends TestCase { * @tests java.nio.charset.CharsetEncoder.CharsetEncoder( * java.nio.charset.Charset, float, float) */ +@TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "CharsetEncoder", + methodArgs = {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); @@ -104,6 +130,15 @@ public class CharsetEncoderTest extends TestCase { /* * Test malfunction encode(CharBuffer) */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "Regression test checks CoderMalfunctionError", + targets = { + @TestTarget( + methodName = "encode", + methodArgs = {java.nio.CharBuffer.class} + ) + }) public void test_EncodeLjava_nio_CharBuffer() throws Exception { MockMalfunctionCharset cs = new MockMalfunctionCharset("mock", null); try { @@ -153,6 +188,15 @@ public class CharsetEncoderTest extends TestCase { /* * Test reserve bytes encode(CharBuffer,ByteBuffer,boolean) */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "Functional test.", + targets = { + @TestTarget( + methodName = "encode", + methodArgs = {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"); diff --git a/nio_char/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/CharsetTest.java b/nio_char/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/CharsetTest.java index 0c46cd9..c912469 100644 --- a/nio_char/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/CharsetTest.java +++ b/nio_char/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/CharsetTest.java @@ -16,6 +16,11 @@ package org.apache.harmony.nio_char.tests.java.nio.charset; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestLevel; + import java.nio.ByteBuffer; import java.nio.CharBuffer; import java.nio.charset.Charset; @@ -29,7 +34,7 @@ import java.util.Properties; import java.util.Set; import junit.framework.TestCase; - +@TestTargetClass(Charset.class) public class CharsetTest extends TestCase { // Will contain names of charsets registered with IANA @@ -56,6 +61,15 @@ public class CharsetTest extends TestCase { /** * @tests java.nio.charset.Charset#isRegistered() */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "isRegistered", + methodArgs = {} + ) + }) public void test_isRegistered() { // Regression for HARMONY-45 for (Iterator nameItr = knownRegisteredCharsets.iterator(); nameItr.hasNext();) { @@ -73,6 +87,15 @@ public class CharsetTest extends TestCase { /** * @tests java.nio.charset.Charset#isSupported(String) */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "Checks IllegalCharsetNameException", + targets = { + @TestTarget( + methodName = "isSupported", + methodArgs = {java.lang.String.class} + ) + }) public void testIsSupported_EmptyString() { // Regression for HARMONY-113 try { @@ -86,6 +109,15 @@ public class CharsetTest extends TestCase { /** * @tests java.nio.charset.Charset#defaultCharset() */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "defaultCharset", + methodArgs = {} + ) + }) public void test_defaultCharset() { String charsetName = null; String defaultCharsetName = null; @@ -135,6 +167,15 @@ public class CharsetTest extends TestCase { /** * @tests java.nio.charset.Charset#forName(java.lang.String) */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "Exceptions checking missed.", + targets = { + @TestTarget( + methodName = "forName", + methodArgs = {java.lang.String.class} + ) + }) public void test_forNameLjava_lang_String() { /* * invoke forName two times with the same canonical name, it @@ -156,6 +197,15 @@ public class CharsetTest extends TestCase { /* * test cached decoder */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "Functional test.", + targets = { + @TestTarget( + methodName = "decode", + methodArgs = {java.nio.ByteBuffer.class} + ) + }) public void test_DecodeLjava_nio_ByteBuffer() throws Exception{ MockCharsetForDecoder cs1 = new MockCharsetForDecoder("CachedCharset",null); MockCharsetForDecoder cs2 = new MockCharsetForDecoder("CachedCharset",null); @@ -218,6 +268,15 @@ public class CharsetTest extends TestCase { /* * test cached encoder */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "Functional test.", + targets = { + @TestTarget( + methodName = "encode", + methodArgs = {java.nio.CharBuffer.class} + ) + }) public void test_EncodeLjava_nio_CharBuffer() throws Exception { MockCharsetForEncoder cs1 = new MockCharsetForEncoder("CachedCharset", null); MockCharsetForEncoder cs2 = new MockCharsetForEncoder("CachedCharset", null); diff --git a/nio_char/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/CoderMalfunctionErrorTest.java b/nio_char/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/CoderMalfunctionErrorTest.java index dc9f269..eefad63 100644 --- a/nio_char/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/CoderMalfunctionErrorTest.java +++ b/nio_char/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/CoderMalfunctionErrorTest.java @@ -16,12 +16,18 @@ package org.apache.harmony.nio_char.tests.java.nio.charset; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestTarget; +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. */ @@ -30,6 +36,15 @@ public class CoderMalfunctionErrorTest extends TestCase { /* * Test constructor with normal param. */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "CoderMalfunctionError", + methodArgs = {java.lang.Exception.class} + ) + }) public void testConstructor_Normal() { Exception ex = new Exception(); CoderMalfunctionError e = new CoderMalfunctionError(ex); @@ -39,6 +54,15 @@ public class CoderMalfunctionErrorTest extends TestCase { /* * Test constructor with null param. */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "CoderMalfunctionError", + methodArgs = {java.lang.Exception.class} + ) + }) public void testConstructor_Null() { CoderMalfunctionError e = new CoderMalfunctionError(null); assertNull(e.getCause()); @@ -47,6 +71,15 @@ public class CoderMalfunctionErrorTest extends TestCase { /** * @tests serialization/deserialization compatibility. */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "Verifies serialization.", + targets = { + @TestTarget( + methodName = "!SerializationSelf", + methodArgs = {} + ) + }) public void testSerializationSelf() throws Exception { SerializationTest.verifySelf(new CoderMalfunctionError(null)); @@ -55,6 +88,15 @@ public class CoderMalfunctionErrorTest extends TestCase { /** * @tests serialization/deserialization compatibility with RI. */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "Verifies serialization.", + targets = { + @TestTarget( + methodName = "!SerializationGolden", + methodArgs = {} + ) + }) public void testSerializationCompatibility() throws Exception { SerializationTest.verifyGolden(this, new CoderMalfunctionError(null)); diff --git a/nio_char/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/IllegalCharsetNameExceptionTest.java b/nio_char/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/IllegalCharsetNameExceptionTest.java index 914eea2..61bdc81 100644 --- a/nio_char/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/IllegalCharsetNameExceptionTest.java +++ b/nio_char/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/IllegalCharsetNameExceptionTest.java @@ -16,6 +16,11 @@ package org.apache.harmony.nio_char.tests.java.nio.charset; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestLevel; + import java.io.Serializable; import java.nio.charset.IllegalCharsetNameException; @@ -24,11 +29,25 @@ 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 { +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "IllegalCharsetNameException", + methodArgs = {java.lang.String.class} + ),@TestTarget( + methodName = "getCharsetName", + methodArgs = {} + ) + + }) public void testConstructor() { IllegalCharsetNameException ex = new IllegalCharsetNameException( "impossible"); @@ -77,6 +96,15 @@ public class IllegalCharsetNameExceptionTest extends TestCase { /** * @tests serialization/deserialization compatibility. */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "Verifies serialization.", + targets = { + @TestTarget( + methodName = "!SerializationSelf", + methodArgs = {} + ) + }) public void testSerializationSelf() throws Exception { SerializationTest.verifySelf(new IllegalCharsetNameException( @@ -86,6 +114,15 @@ public class IllegalCharsetNameExceptionTest extends TestCase { /** * @tests serialization/deserialization compatibility with RI. */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "Verifies serialization.", + targets = { + @TestTarget( + methodName = "!SerializationGolden", + methodArgs = {} + ) + }) public void testSerializationCompatibility() throws Exception { SerializationTest.verifyGolden(this, new IllegalCharsetNameException( diff --git a/nio_char/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/MalformedInputExceptionTest.java b/nio_char/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/MalformedInputExceptionTest.java index 40ab9c7..4ec998f 100644 --- a/nio_char/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/MalformedInputExceptionTest.java +++ b/nio_char/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/MalformedInputExceptionTest.java @@ -16,6 +16,11 @@ package org.apache.harmony.nio_char.tests.java.nio.charset; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestLevel; + import java.io.Serializable; import java.nio.charset.CharacterCodingException; import java.nio.charset.MalformedInputException; @@ -25,11 +30,27 @@ 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 { +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "MalformedInputException", + methodArgs = {int.class} + ),@TestTarget( + methodName = "getMessage", + methodArgs = {} + ),@TestTarget( + methodName = "getInputLength", + methodArgs = {} + ) + }) public void testConstructor() { MalformedInputException ex = new MalformedInputException(3); assertTrue(ex instanceof CharacterCodingException); @@ -68,6 +89,15 @@ public class MalformedInputExceptionTest extends TestCase { /** * @tests serialization/deserialization compatibility. */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "Verifies serialization.", + targets = { + @TestTarget( + methodName = "!SerializationSelf", + methodArgs = {} + ) + }) public void testSerializationSelf() throws Exception { SerializationTest.verifySelf(new MalformedInputException(11), @@ -77,6 +107,15 @@ public class MalformedInputExceptionTest extends TestCase { /** * @tests serialization/deserialization compatibility with RI. */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "Verifies serialization.", + targets = { + @TestTarget( + methodName = "!SerializationGolden", + methodArgs = {} + ) + }) public void testSerializationCompatibility() throws Exception { SerializationTest.verifyGolden(this, new MalformedInputException(11), diff --git a/nio_char/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/UnmappableCharacterExceptionTest.java b/nio_char/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/UnmappableCharacterExceptionTest.java index 0abefbe..cbd256a 100644 --- a/nio_char/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/UnmappableCharacterExceptionTest.java +++ b/nio_char/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/UnmappableCharacterExceptionTest.java @@ -16,6 +16,11 @@ package org.apache.harmony.nio_char.tests.java.nio.charset; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestLevel; + import java.io.Serializable; import java.nio.charset.CharacterCodingException; import java.nio.charset.UnmappableCharacterException; @@ -25,11 +30,27 @@ 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 { +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "UnmappableCharacterException", + methodArgs = {int.class} + ), @TestTarget( + methodName = "getMessage", + methodArgs = {} + ), @TestTarget( + methodName = "getInputLength", + methodArgs = {} + ) + }) public void testConstructor() { UnmappableCharacterException ex = new UnmappableCharacterException(3); assertTrue(ex instanceof CharacterCodingException); @@ -69,6 +90,15 @@ public class UnmappableCharacterExceptionTest extends TestCase { /** * @tests serialization/deserialization compatibility. */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "Verifies serialization.", + targets = { + @TestTarget( + methodName = "!SerializationSelf", + methodArgs = {} + ) + }) public void testSerializationSelf() throws Exception { SerializationTest.verifySelf(new UnmappableCharacterException(11), @@ -78,6 +108,15 @@ public class UnmappableCharacterExceptionTest extends TestCase { /** * @tests serialization/deserialization compatibility with RI. */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "Verifies serialization.", + targets = { + @TestTarget( + methodName = "!SerializationGolden", + methodArgs = {} + ) + }) public void testSerializationCompatibility() throws Exception { SerializationTest.verifyGolden(this, new UnmappableCharacterException( diff --git a/nio_char/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/UnsupportedCharsetExceptionTest.java b/nio_char/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/UnsupportedCharsetExceptionTest.java index dd17848..ca736e2 100644 --- a/nio_char/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/UnsupportedCharsetExceptionTest.java +++ b/nio_char/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/UnsupportedCharsetExceptionTest.java @@ -16,6 +16,11 @@ package org.apache.harmony.nio_char.tests.java.nio.charset; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestLevel; + import java.io.Serializable; import java.nio.charset.UnsupportedCharsetException; @@ -24,11 +29,25 @@ 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 { +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "UnsupportedCharsetException", + methodArgs = {java.lang.String.class} + ),@TestTarget( + methodName = "getCharsetName", + methodArgs = {} + ) + + }) public void testConstructor() { UnsupportedCharsetException ex = new UnsupportedCharsetException( "impossible"); @@ -76,6 +95,15 @@ public class UnsupportedCharsetExceptionTest extends TestCase { /** * @tests serialization/deserialization compatibility. */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "Verifies serialization.", + targets = { + @TestTarget( + methodName = "!SerializationSelf", + methodArgs = {} + ) + }) public void testSerializationSelf() throws Exception { SerializationTest.verifySelf(new UnsupportedCharsetException( @@ -85,6 +113,15 @@ public class UnsupportedCharsetExceptionTest extends TestCase { /** * @tests serialization/deserialization compatibility with RI. */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "Verifies serialization.", + targets = { + @TestTarget( + methodName = "!SerializationGolden", + methodArgs = {} + ) + }) public void testSerializationCompatibility() throws Exception { SerializationTest.verifyGolden(this, new UnsupportedCharsetException( diff --git a/nio_char/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/spi/CharsetProviderTest.java b/nio_char/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/spi/CharsetProviderTest.java index 7a90b56..4321479 100644 --- a/nio_char/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/spi/CharsetProviderTest.java +++ b/nio_char/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/spi/CharsetProviderTest.java @@ -16,13 +16,18 @@ package org.apache.harmony.nio_char.tests.java.nio.charset.spi; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestTarget; +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. */ @@ -31,6 +36,15 @@ public class CharsetProviderTest extends TestCase { /* * Test the security check in the constructor. */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "Normal condition does not checked.", + targets = { + @TestTarget( + methodName = "CharsetProvider", + methodArgs = {} + ) + }) public void testConstructor() { // with sufficient privilege new MockCharsetProvider(); diff --git a/nio_char/src/test/java/tests/api/java/nio/charset/ASCCharsetDecoderTest.java b/nio_char/src/test/java/tests/api/java/nio/charset/ASCCharsetDecoderTest.java index 5dcf956..d41f5bf 100644 --- a/nio_char/src/test/java/tests/api/java/nio/charset/ASCCharsetDecoderTest.java +++ b/nio_char/src/test/java/tests/api/java/nio/charset/ASCCharsetDecoderTest.java @@ -16,10 +16,13 @@ package tests.api.java.nio.charset; +import dalvik.annotation.TestTargetClass; + import java.io.UnsupportedEncodingException; import java.nio.ByteBuffer; import java.nio.charset.Charset; +@TestTargetClass(java.nio.charset.CharsetDecoder.class) public class ASCCharsetDecoderTest extends CharsetDecoderTest { protected void setUp() throws Exception { diff --git a/nio_char/src/test/java/tests/api/java/nio/charset/ASCCharsetTest.java b/nio_char/src/test/java/tests/api/java/nio/charset/ASCCharsetTest.java index d907e93..7d0e366 100644 --- a/nio_char/src/test/java/tests/api/java/nio/charset/ASCCharsetTest.java +++ b/nio_char/src/test/java/tests/api/java/nio/charset/ASCCharsetTest.java @@ -16,6 +16,12 @@ package tests.api.java.nio.charset; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestLevel; + +@TestTargetClass(java.nio.charset.Charset.class) /** * Test charset US-ASCII. */ @@ -37,6 +43,15 @@ public class ASCCharsetTest extends AbstractCharsetTestCase { * * @see tests.api.java.nio.charset.ConcreteCharsetTest#testEncode_Normal() */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "IllegalStateException checking missed.", + targets = { + @TestTarget( + methodName = "encode", + methodArgs = {java.lang.String.class} + ) + }) public void testEncode_Normal() { String input = "ab\u5D14\u654F"; byte[] output = new byte[] { 97, 98, @@ -50,6 +65,15 @@ public class ASCCharsetTest extends AbstractCharsetTestCase { * * @see tests.api.java.nio.charset.ConcreteCharsetTest#testDecode_Normal() */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "IllegalStateException checking missed.", + targets = { + @TestTarget( + methodName = "decode", + methodArgs = {java.nio.ByteBuffer.class} + ) + }) public void testDecode_Normal() { byte[] input = new byte[] { 97, 98, 63, 63 }; char[] output = "ab??".toCharArray(); diff --git a/nio_char/src/test/java/tests/api/java/nio/charset/AbstractCharsetTestCase.java b/nio_char/src/test/java/tests/api/java/nio/charset/AbstractCharsetTestCase.java index 9a9b45c..6ded102 100644 --- a/nio_char/src/test/java/tests/api/java/nio/charset/AbstractCharsetTestCase.java +++ b/nio_char/src/test/java/tests/api/java/nio/charset/AbstractCharsetTestCase.java @@ -1,11 +1,16 @@ package tests.api.java.nio.charset; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestLevel; + import java.nio.ByteBuffer; import java.nio.CharBuffer; import java.nio.charset.Charset; import junit.framework.TestCase; - +@TestTargetClass(java.nio.charset.Charset.class) /** * Super class for concrete charset test suites. */ @@ -59,6 +64,15 @@ public abstract class AbstractCharsetTestCase extends TestCase { /* * Test canEncode. */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "", + targets = { + @TestTarget( + methodName = "canEncode", + methodArgs = {} + ) + }) public void testCanEncode() { assertEquals(this.canEncode, this.testingCharset.canEncode()); } @@ -66,6 +80,15 @@ public abstract class AbstractCharsetTestCase extends TestCase { /* * Test isRegistered. */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "", + targets = { + @TestTarget( + methodName = "isRegistered", + methodArgs = {} + ) + }) public void testIsRegistered() { assertEquals(this.isRegistered, this.testingCharset.isRegistered()); } @@ -73,6 +96,15 @@ public abstract class AbstractCharsetTestCase extends TestCase { /* * Test name. */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "", + targets = { + @TestTarget( + methodName = "name", + methodArgs = {} + ) + }) public void testName() { assertEquals(this.canonicalName, this.testingCharset.name()); // assertEquals(this.canonicalName, this.testingCharset.displayName()); @@ -83,6 +115,15 @@ public abstract class AbstractCharsetTestCase extends TestCase { /* * Test aliases. */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "Test functionality completely missed.", + targets = { + @TestTarget( + methodName = "aliases", + methodArgs = {} + ) + }) public void testAliases() { for (int i = 0; i < this.aliases.length; i++) { Charset c = Charset.forName(this.aliases[i]); @@ -95,6 +136,15 @@ public abstract class AbstractCharsetTestCase extends TestCase { /* * Test the method encode(String) with null. */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "", + targets = { + @TestTarget( + methodName = "encode", + methodArgs = {java.lang.String.class} + ) + }) public void testEncode_String_Null() { try { this.testingCharset.encode((String) null); @@ -107,6 +157,15 @@ public abstract class AbstractCharsetTestCase extends TestCase { /* * Test the method encode(CharBuffer) with null. */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "", + targets = { + @TestTarget( + methodName = "encode", + methodArgs = {java.nio.CharBuffer.class} + ) + }) public void testEncode_CharBuffer_Null() { try { this.testingCharset.encode((CharBuffer) null); @@ -134,6 +193,15 @@ public abstract class AbstractCharsetTestCase extends TestCase { /* * Test encoding. */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "Super class for testing.", + targets = { + @TestTarget( + methodName = "", + methodArgs = {} + ) + }) public abstract void testEncode_Normal(); /* @@ -154,5 +222,14 @@ public abstract class AbstractCharsetTestCase extends TestCase { /* * Test decoding. */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "Super class for testing.", + targets = { + @TestTarget( + methodName = "", + methodArgs = {} + ) + }) public abstract void testDecode_Normal(); } diff --git a/nio_char/src/test/java/tests/api/java/nio/charset/AllTests.java b/nio_char/src/test/java/tests/api/java/nio/charset/AllTests.java index e718651..666d698 100644 --- a/nio_char/src/test/java/tests/api/java/nio/charset/AllTests.java +++ b/nio_char/src/test/java/tests/api/java/nio/charset/AllTests.java @@ -1,12 +1,12 @@ -/* Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * +/* + * 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. @@ -16,46 +16,50 @@ package tests.api.java.nio.charset; -import org.apache.harmony.nio_char.tests.java.nio.charset.ASCIICharsetEncoderTest; - import junit.framework.Test; import junit.framework.TestSuite; /** - * Test suite for java.nio.charset package. + * This is autogenerated source file. Includes tests for package tests.api.java.nio.charset; */ + public class AllTests { + public static void main(String[] args) { + junit.textui.TestRunner.run(AllTests.suite()); + } + public static Test suite() { - TestSuite suite = new TestSuite("Test for tests.api.java.nio.charset"); + TestSuite suite = new TestSuite("All tests for package tests.api.java.nio.charset;"); // $JUnit-BEGIN$ - suite.addTestSuite(CodingErrorActionTest.class); - suite.addTestSuite(CoderResultTest.class); - suite.addTestSuite(CharsetTest.class); + + suite.addTestSuite(ASCCharsetDecoderTest.class); suite.addTestSuite(ASCCharsetTest.class); - suite.addTestSuite(ISOCharsetTest.class); - suite.addTestSuite(UTF8CharsetTest.class); - suite.addTestSuite(UTF16CharsetTest.class); - suite.addTestSuite(UTF16BECharsetTest.class); - suite.addTestSuite(UTF16LECharsetTest.class); + suite.addTestSuite(CharsetDecoderTest.class); suite.addTestSuite(CharsetEncoderTest.class); + suite.addTestSuite(CharsetProviderTest.class); + suite.addTestSuite(CharsetTest.class); + suite.addTestSuite(CoderResultTest.class); + suite.addTestSuite(CodingErrorActionTest.class); +// GBCharset not supported +// suite.addTestSuite(GBCharsetDecoderTest.class); +// suite.addTestSuite(GBCharsetEncoderTest.class); + suite.addTestSuite(ISOCharsetDecoderTest.class); suite.addTestSuite(ISOCharsetEncoderTest.class); - suite.addTestSuite(UTFCharsetEncoderTest.class); - // GBCharset not supported - // suite.addTestSuite(GBCharsetEncoderTest.class); - suite.addTestSuite(ASCIICharsetEncoderTest.class); - suite.addTestSuite(UTF16CharsetEncoderTest.class); - suite.addTestSuite(UTF16LECharsetEncoderTest.class); + suite.addTestSuite(ISOCharsetTest.class); + suite.addTestSuite(UTF16BECharsetDecoderTest.class); suite.addTestSuite(UTF16BECharsetEncoderTest.class); - suite.addTestSuite(CharsetDecoderTest.class); - suite.addTestSuite(ISOCharsetDecoderTest.class); - suite.addTestSuite(UTFCharsetDecoderTest.class); - // GBCharset not supported - // suite.addTestSuite(GBCharsetDecoderTest.class); - suite.addTestSuite(ASCCharsetDecoderTest.class); + suite.addTestSuite(UTF16BECharsetTest.class); suite.addTestSuite(UTF16CharsetDecoderTest.class); + suite.addTestSuite(UTF16CharsetEncoderTest.class); + suite.addTestSuite(UTF16CharsetTest.class); suite.addTestSuite(UTF16LECharsetDecoderTest.class); - suite.addTestSuite(UTF16BECharsetDecoderTest.class); + suite.addTestSuite(UTF16LECharsetEncoderTest.class); + suite.addTestSuite(UTF16LECharsetTest.class); + suite.addTestSuite(UTF8CharsetTest.class); + suite.addTestSuite(UTFCharsetDecoderTest.class); + suite.addTestSuite(UTFCharsetEncoderTest.class); + // $JUnit-END$ return suite; } diff --git a/nio_char/src/test/java/tests/api/java/nio/charset/CharsetDecoderTest.java b/nio_char/src/test/java/tests/api/java/nio/charset/CharsetDecoderTest.java index 0d067b0..74bb852 100644 --- a/nio_char/src/test/java/tests/api/java/nio/charset/CharsetDecoderTest.java +++ b/nio_char/src/test/java/tests/api/java/nio/charset/CharsetDecoderTest.java @@ -15,6 +15,11 @@ */ package tests.api.java.nio.charset; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestLevel; + import java.io.UnsupportedEncodingException; import java.nio.ByteBuffer; import java.nio.CharBuffer; @@ -27,7 +32,7 @@ import java.nio.charset.MalformedInputException; import java.nio.charset.UnmappableCharacterException; import junit.framework.TestCase; - +@TestTargetClass(CharsetDecoder.class) /** * API unit test for java.nio.CharsetDecoder */ @@ -70,6 +75,33 @@ public class CharsetDecoderTest extends TestCase { // assertTrue(decoder.maxCharsPerByte() == MAX_BYTES); // } +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "charset", + methodArgs = {} + ), @TestTarget( + methodName = "detectedCharset", + methodArgs = {} + ), @TestTarget( + methodName = "isCharsetDetected", + methodArgs = {} + ), @TestTarget( + methodName = "isAutoDetecting", + methodArgs = {} + ), @TestTarget( + methodName = "malformedInputAction", + methodArgs = {} + ), @TestTarget( + methodName = "unmappableCharacterAction", + methodArgs = {} + ), @TestTarget( + methodName = "replacement", + methodArgs = {} + ) + }) public void testDefaultValues() { assertSame(cs, decoder.charset()); try { @@ -92,6 +124,24 @@ public class CharsetDecoderTest extends TestCase { /* * test constructor */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "CharsetDecoder", + methodArgs = {java.nio.charset.Charset.class, float.class, float.class} + ), @TestTarget( + methodName = "charset", + methodArgs = {} + ), @TestTarget( + methodName = "averageCharsPerByte", + methodArgs = {} + ), @TestTarget( + methodName = "maxCharsPerByte", + methodArgs = {} + ) + }) public void testCharsetDecoder() { // default value decoder = new MockCharsetDecoder(cs, (float) AVER_BYTES, MAX_BYTES); @@ -148,6 +198,18 @@ public class CharsetDecoderTest extends TestCase { /* * test onMalformedInput */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "malformedInputAction", + methodArgs = {} + ), @TestTarget( + methodName = "onMalformedInput", + methodArgs = {java.nio.charset.CodingErrorAction.class} + ) + }) public void testOnMalformedInput() { assertSame(CodingErrorAction.REPORT, decoder.malformedInputAction()); try { @@ -162,6 +224,18 @@ public class CharsetDecoderTest extends TestCase { /* * test unmappableCharacter */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "unmappableCharacterAction", + methodArgs = {} + ), @TestTarget( + methodName = "onUnmappableCharacter", + methodArgs = {java.nio.charset.CodingErrorAction.class} + ) + }) public void testOnUnmappableCharacter() { assertSame(CodingErrorAction.REPORT, decoder .unmappableCharacterAction()); @@ -178,6 +252,18 @@ public class CharsetDecoderTest extends TestCase { /* * test replaceWith */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "replaceWith", + methodArgs = {java.lang.String.class} + ), @TestTarget( + methodName = "replacement", + methodArgs = {} + ) + }) public void testReplaceWith() { try { decoder.replaceWith(null); @@ -202,6 +288,15 @@ public class CharsetDecoderTest extends TestCase { /* * Class under test for CharBuffer decode(ByteBuffer) */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "IllegalStateException & CharacterCodingException checking missed.", + targets = { + @TestTarget( + methodName = "decode", + methodArgs = {java.nio.ByteBuffer.class} + ) + }) public void testDecodeByteBuffer() throws CharacterCodingException { implTestDecodeByteBuffer(); } @@ -227,6 +322,15 @@ public class CharsetDecoderTest extends TestCase { assertEquals(new String(out.array(), 0, out.limit()), unistr); } +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "IllegalStateException & CharacterCodingException checking missed.", + targets = { + @TestTarget( + methodName = "decode", + methodArgs = {java.nio.ByteBuffer.class} + ) + }) public void testDecodeByteBufferException() throws CharacterCodingException, UnsupportedEncodingException { CharBuffer out; @@ -293,6 +397,16 @@ public class CharsetDecoderTest extends TestCase { /* * Class under test for CoderResult decode(ByteBuffer, CharBuffer, boolean) */ + +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "Functional test. Exceptions checking missed.", + targets = { + @TestTarget( + methodName = "decode", + methodArgs = {java.nio.ByteBuffer.class, java.nio.CharBuffer.class, boolean.class} + ) + }) public void testDecodeByteBufferCharBufferboolean() { implTestDecodeByteBufferCharBufferboolean(); } @@ -369,11 +483,29 @@ public class CharsetDecoderTest extends TestCase { assertCharBufferValue(out, bom + unistr); } +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "Functional test. Exceptions checking missed.", + targets = { + @TestTarget( + methodName = "decode", + methodArgs = {java.nio.ByteBuffer.class, java.nio.CharBuffer.class, boolean.class} + ) + }) public void testDecodeCharBufferByteBufferbooleanExceptionTrue() throws CharacterCodingException, UnsupportedEncodingException { implTestDecodeCharBufferByteBufferbooleanException(true); } +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "Functional test. Exceptions checking missed.", + targets = { + @TestTarget( + methodName = "decode", + methodArgs = {java.nio.ByteBuffer.class, java.nio.CharBuffer.class, boolean.class} + ) + }) public void testDecodeCharBufferByteBufferbooleanExceptionFalse() throws CharacterCodingException, UnsupportedEncodingException { implTestDecodeCharBufferByteBufferbooleanException(false); @@ -482,6 +614,15 @@ public class CharsetDecoderTest extends TestCase { /* * test flush */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "IllegalStateException checking missed.", + targets = { + @TestTarget( + methodName = "flush", + methodArgs = {java.nio.CharBuffer.class} + ) + }) public void testFlush() throws CharacterCodingException { CharBuffer out = CharBuffer.allocate(10); ByteBuffer in = ByteBuffer.wrap(new byte[] { 12, 12 }); @@ -501,6 +642,15 @@ public class CharsetDecoderTest extends TestCase { */ // Normal case: just after reset, and it also means reset can be done // anywhere +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "reset", + methodArgs = {} + ) + }) public void testResetIllegalState() throws CharacterCodingException { byte[] gb = getUnibytes(); decoder.reset(); @@ -512,6 +662,18 @@ public class CharsetDecoderTest extends TestCase { decoder.reset(); } +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "flush", + methodArgs = {java.nio.CharBuffer.class} + ), @TestTarget( + methodName = "reset", + methodArgs = {} + ) + }) public void testFlushIllegalState() throws CharacterCodingException { ByteBuffer in = ByteBuffer.wrap(new byte[] { 98, 98 }); CharBuffer out = CharBuffer.allocate(5); @@ -544,6 +706,18 @@ public class CharsetDecoderTest extends TestCase { } // test illegal states for decode facade +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "Exceptions checking missed", + targets = { + @TestTarget( + methodName = "decode", + methodArgs = {java.nio.ByteBuffer.class} + ), @TestTarget( + methodName = "decode", + methodArgs = {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(); @@ -577,6 +751,15 @@ public class CharsetDecoderTest extends TestCase { } // test illegal states for two decode method with endOfInput is true +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "CoderMalfunctionError checking missed", + targets = { + @TestTarget( + methodName = "decode", + methodArgs = {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); @@ -617,6 +800,15 @@ public class CharsetDecoderTest extends TestCase { } // test illegal states for two decode method with endOfInput is false +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "CoderMalfunctionError checking missed", + targets = { + @TestTarget( + methodName = "decode", + methodArgs = {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); @@ -674,12 +866,30 @@ public class CharsetDecoderTest extends TestCase { * --------------------------------- */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "implFlush", + methodArgs = {java.nio.CharBuffer.class} + ) + }) public void testImplFlush() { decoder = new MockCharsetDecoder(cs, 1, 3); assertEquals(CoderResult.UNDERFLOW, ((MockCharsetDecoder) decoder) .pubImplFlush(null)); } +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "implOnMalformedInput", + methodArgs = {java.nio.charset.CodingErrorAction.class} + ) + }) public void testImplOnMalformedInput() { decoder = new MockCharsetDecoder(cs, 1, 3); assertEquals(CoderResult.UNDERFLOW, ((MockCharsetDecoder) decoder) @@ -687,16 +897,43 @@ public class CharsetDecoderTest extends TestCase { } +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "implOnUnmappableCharacter", + methodArgs = {java.nio.charset.CodingErrorAction.class} + ) + }) public void testImplOnUnmappableCharacter() { decoder = new MockCharsetDecoder(cs, 1, 3); ((MockCharsetDecoder) decoder).pubImplOnUnmappableCharacter(null); } +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "implReplaceWith", + methodArgs = {java.lang.String.class} + ) + }) public void testImplReplaceWith() { decoder = new MockCharsetDecoder(cs, 1, 3); ((MockCharsetDecoder) decoder).pubImplReplaceWith(null); } +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "implReset", + methodArgs = {} + ) + }) public void testImplReset() { decoder = new MockCharsetDecoder(cs, 1, 3); ((MockCharsetDecoder) decoder).pubImplReset(); diff --git a/nio_char/src/test/java/tests/api/java/nio/charset/CharsetEncoderTest.java b/nio_char/src/test/java/tests/api/java/nio/charset/CharsetEncoderTest.java index 3284a57..475cd87 100644 --- a/nio_char/src/test/java/tests/api/java/nio/charset/CharsetEncoderTest.java +++ b/nio_char/src/test/java/tests/api/java/nio/charset/CharsetEncoderTest.java @@ -15,6 +15,11 @@ */ package tests.api.java.nio.charset; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestLevel; + import java.nio.ByteBuffer; import java.nio.CharBuffer; import java.nio.charset.CharacterCodingException; @@ -29,7 +34,7 @@ import java.nio.charset.UnsupportedCharsetException; import java.util.Arrays; import junit.framework.TestCase; - +@TestTargetClass(CharsetEncoder.class) /** * API unit test for java.nio.charset.CharsetEncoder */ @@ -81,11 +86,44 @@ public class CharsetEncoderTest extends TestCase { super.tearDown(); } +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "averageBytesPerChar", + methodArgs = {} + ), @TestTarget( + methodName = "maxBytesPerChar", + methodArgs = {} + ) + }) public void testSpecificDefaultValue() { assertTrue(encoder.averageBytesPerChar() == AVER_BYTES); assertTrue(encoder.maxBytesPerChar() == MAX_BYTES); } +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "onMalformedInput & onUnmappableCharacter requires check for IllegalArgumentException", + targets = { + @TestTarget( + methodName = "malformedInputAction", + methodArgs = {} + ), @TestTarget( + methodName = "unmappableCharacterAction", + methodArgs = {} + ), @TestTarget( + methodName = "onMalformedInput", + methodArgs = {java.nio.charset.CodingErrorAction.class} + ), @TestTarget( + methodName = "onUnmappableCharacter", + methodArgs = {java.nio.charset.CodingErrorAction.class} + ), @TestTarget( + methodName = "replacement", + methodArgs = {} + ) + }) public void testDefaultValue() { assertEquals(CodingErrorAction.REPORT, encoder.malformedInputAction()); assertEquals(CodingErrorAction.REPORT, encoder @@ -105,6 +143,33 @@ public class CharsetEncoderTest extends TestCase { /* * Class under test for constructor CharsetEncoder(Charset, float, float) */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "charset", + methodArgs = {} + ), @TestTarget( + methodName = "averageBytesPerChar", + methodArgs = {} + ), @TestTarget( + methodName = "maxBytesPerChar", + methodArgs = {} + ), @TestTarget( + methodName = "malformedInputAction", + methodArgs = {} + ), @TestTarget( + methodName = "unmappableCharacterAction", + methodArgs = {} + ), @TestTarget( + methodName = "CharsetEncoder", + methodArgs = {java.nio.charset.Charset.class, float.class, float.class} + ), @TestTarget( + methodName = "replacement", + methodArgs = {} + ) + }) public void testCharsetEncoderCharsetfloatfloat() { // default value encoder = new MockCharsetEncoder(cs, (float) AVER_BYTES, MAX_BYTES); @@ -174,6 +239,27 @@ public class CharsetEncoderTest extends TestCase { * Class under test for constructor CharsetEncoder(Charset, float, float, * byte[]) */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "CharsetEncoder", + methodArgs = {java.nio.charset.Charset.class, float.class, float.class, byte[].class} + ), @TestTarget( + methodName = "charset", + methodArgs = {} + ), @TestTarget( + methodName = "averageBytesPerChar", + methodArgs = {} + ), @TestTarget( + methodName = "maxBytesPerChar", + methodArgs = {} + ), @TestTarget( + methodName = "replacement", + methodArgs = {} + ) + }) public void testCharsetEncoderCharsetfloatfloatbyteArray() { byte[] ba = getLegalByteArray(); // normal case @@ -248,6 +334,15 @@ public class CharsetEncoderTest extends TestCase { /* * Class under test for boolean canEncode(char) */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "IllegalStateException checking missed.", + targets = { + @TestTarget( + methodName = "canEncode", + methodArgs = {char.class} + ) + }) public void testCanEncodechar() throws CharacterCodingException { // for non-mapped char assertTrue(encoder.canEncode('\uc2c0')); @@ -267,6 +362,27 @@ public class CharsetEncoderTest extends TestCase { // Normal case: just after reset, and it also means reset can be done // anywhere +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "Exceptions checking missed.", + targets = { + @TestTarget( + methodName = "canEncode", + methodArgs = {char.class} + ), @TestTarget( + methodName = "canEncode", + methodArgs = {java.lang.CharSequence.class} + ), @TestTarget( + methodName = "encode", + methodArgs = {java.nio.CharBuffer.class} + ), @TestTarget( + methodName = "encode", + methodArgs = {java.nio.CharBuffer.class, java.nio.ByteBuffer.class, boolean.class} + ), @TestTarget( + methodName = "reset", + methodArgs = {} + ) + }) public void testResetIllegalState() throws CharacterCodingException { assertSame(encoder, encoder.reset()); encoder.canEncode('\ud901'); @@ -281,6 +397,18 @@ public class CharsetEncoderTest extends TestCase { assertSame(encoder, encoder.reset()); } +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "reset", + methodArgs = {} + ), @TestTarget( + methodName = "flush", + methodArgs = {java.nio.ByteBuffer.class} + ) + }) public void testFlushIllegalState() throws CharacterCodingException { CharBuffer in = CharBuffer.wrap("aaa"); ByteBuffer out = ByteBuffer.allocate(5); @@ -309,6 +437,27 @@ public class CharsetEncoderTest extends TestCase { } // test illegal states for encode facade +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "Exceptions checking missed.", + targets = { + @TestTarget( + methodName = "encode", + methodArgs = {java.nio.CharBuffer.class} + ), @TestTarget( + methodName = "canEncode", + methodArgs = {char.class} + ), @TestTarget( + methodName = "canEncode", + methodArgs = {java.lang.CharSequence.class} + ), @TestTarget( + methodName = "encode", + methodArgs = {java.nio.CharBuffer.class, java.nio.ByteBuffer.class, boolean.class} + ), @TestTarget( + methodName = "flush", + methodArgs = {java.nio.ByteBuffer.class} + ) + }) public void testEncodeFacadeIllegalState() throws CharacterCodingException { // encode facade can be execute in anywhere CharBuffer in = CharBuffer.wrap("aaa"); @@ -354,6 +503,27 @@ public class CharsetEncoderTest extends TestCase { } // test illegal states for two encode method with endOfInput is true +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "Exceptions checking missed.", + targets = { + @TestTarget( + methodName = "encode", + methodArgs = {java.nio.CharBuffer.class, java.nio.ByteBuffer.class, boolean.class} + ), @TestTarget( + methodName = "canEncode", + methodArgs = {char.class} + ), @TestTarget( + methodName = "canEncode", + methodArgs = {java.lang.CharSequence.class} + ), @TestTarget( + methodName = "reset", + methodArgs = {} + ), @TestTarget( + methodName = "flush", + methodArgs = {java.nio.ByteBuffer.class} + ) + }) public void testEncodeTrueIllegalState() throws CharacterCodingException { CharBuffer in = CharBuffer.wrap("aaa"); ByteBuffer out = ByteBuffer.allocate(5); @@ -404,6 +574,30 @@ public class CharsetEncoderTest extends TestCase { } // test illegal states for two encode method with endOfInput is false +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "", + targets = { + @TestTarget( + methodName = "encode", + methodArgs = {java.nio.CharBuffer.class, java.nio.ByteBuffer.class, boolean.class} + ), @TestTarget( + methodName = "encode", + methodArgs = {java.nio.CharBuffer.class} + ), @TestTarget( + methodName = "canEncode", + methodArgs = {char.class} + ), @TestTarget( + methodName = "canEncode", + methodArgs = {java.lang.CharSequence.class} + ), @TestTarget( + methodName = "reset", + methodArgs = {} + ), @TestTarget( + methodName = "flush", + methodArgs = {java.nio.ByteBuffer.class} + ) + }) public void testEncodeFalseIllegalState() throws CharacterCodingException { CharBuffer in = CharBuffer.wrap("aaa"); ByteBuffer out = ByteBuffer.allocate(5); @@ -462,6 +656,24 @@ public class CharsetEncoderTest extends TestCase { } // test illegal states for two canEncode methods +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "canEncode", + methodArgs = {char.class} + ), @TestTarget( + methodName = "canEncode", + methodArgs = {java.lang.CharSequence.class} + ), @TestTarget( + methodName = "reset", + methodArgs = {} + ), @TestTarget( + methodName = "flush", + methodArgs = {java.nio.ByteBuffer.class} + ) + }) public void testCanEncodeIllegalState() throws CharacterCodingException { // Normal case: just created encoder.canEncode("\ud900\udc00"); @@ -508,6 +720,15 @@ public class CharsetEncoderTest extends TestCase { /* * Class under test for boolean canEncode(CharSequence) */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "IllegalStateException checking missed.", + targets = { + @TestTarget( + methodName = "canEncode", + methodArgs = {java.lang.CharSequence.class} + ) + }) public void testCanEncodeCharSequence() { // for non-mapped char assertTrue(encoder.canEncode("\uc2c0")); @@ -524,6 +745,15 @@ public class CharsetEncoderTest extends TestCase { /* * Class under test for Charset charset() */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "", + targets = { + @TestTarget( + methodName = "CharsetEncoder", + methodArgs = {java.nio.charset.Charset.class, float.class, float.class} + ) + }) public void testCharset() { try { encoder = new MockCharsetEncoder(Charset.forName("gbk"), 1, @@ -538,6 +768,15 @@ public class CharsetEncoderTest extends TestCase { /* * Class under test for ByteBuffer encode(CharBuffer) */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "Functional test. Exceptions checking missed.", + targets = { + @TestTarget( + methodName = "encode", + methodArgs = {java.nio.CharBuffer.class} + ) + }) public void testEncodeCharBuffer() throws CharacterCodingException { // Null pointer try { @@ -598,6 +837,15 @@ public class CharsetEncoderTest extends TestCase { return CharBuffer.wrap("runtime buffer"); } +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "Missed checking for IllegalStateException & CharacterCodingException", + targets = { + @TestTarget( + methodName = "encode", + methodArgs = {java.nio.CharBuffer.class} + ) + }) public void testEncodeCharBufferException() throws CharacterCodingException { ByteBuffer out; CharBuffer in; @@ -677,6 +925,15 @@ public class CharsetEncoderTest extends TestCase { /* * Class under test for CoderResult encode(CharBuffer, ByteBuffer, boolean) */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "Functional test. Exceptions checking missed.", + targets = { + @TestTarget( + methodName = "encode", + methodArgs = {java.nio.CharBuffer.class, java.nio.ByteBuffer.class, boolean.class} + ) + }) public void testEncodeCharBufferByteBufferboolean() throws CharacterCodingException { ByteBuffer out = ByteBuffer.allocate(200); @@ -782,11 +1039,29 @@ public class CharsetEncoderTest extends TestCase { } } + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Functional test. Exceptions checking missed.", + targets = { + @TestTarget( + methodName = "encode", + methodArgs = {java.nio.CharBuffer.class, java.nio.ByteBuffer.class, boolean.class} + ) + }) public void testEncodeCharBufferByteBufferbooleanExceptionFalse() throws CharacterCodingException { implTestEncodeCharBufferByteBufferbooleanException(false); } + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Functional test. Exceptions checking missed.", + targets = { + @TestTarget( + methodName = "encode", + methodArgs = {java.nio.CharBuffer.class, java.nio.ByteBuffer.class, boolean.class} + ) + }) public void testEncodeCharBufferByteBufferbooleanExceptionTrue() throws CharacterCodingException { implTestEncodeCharBufferByteBufferbooleanException(true); @@ -887,6 +1162,15 @@ public class CharsetEncoderTest extends TestCase { /* * Class under test for CoderResult flush(ByteBuffer) */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "Exceptions checking missed.", + targets = { + @TestTarget( + methodName = "encode", + methodArgs = {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"); @@ -902,6 +1186,15 @@ public class CharsetEncoderTest extends TestCase { /* * test isLegalReplacement(byte[]) */ +@TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "isLegalReplacement", + methodArgs = {byte[].class} + ) + }) public void testIsLegalReplacement() { try { encoder.isLegalReplacement(null); @@ -917,6 +1210,15 @@ public class CharsetEncoderTest extends TestCase { } } +@TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "isLegalReplacement", + methodArgs = {byte[].class} + ) + }) public void testIsLegalReplacementEmptyArray() { // ISO, ASC, GB, UTF8 encoder will throw exception in RI // others will pass @@ -927,6 +1229,18 @@ public class CharsetEncoderTest extends TestCase { // } } +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "onMalformedInput", + methodArgs = {java.nio.charset.CodingErrorAction.class} + ), @TestTarget( + methodName = "malformedInputAction", + methodArgs = {} + ) + }) public void testOnMalformedInput() { assertSame(CodingErrorAction.REPORT, encoder.malformedInputAction()); try { @@ -938,6 +1252,18 @@ public class CharsetEncoderTest extends TestCase { assertSame(CodingErrorAction.IGNORE, encoder.malformedInputAction()); } +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "onUnmappableCharacter", + methodArgs = {java.nio.charset.CodingErrorAction.class} + ), @TestTarget( + methodName = "unmappableCharacterAction", + methodArgs = {} + ) + }) public void testOnUnmappableCharacter() { assertSame(CodingErrorAction.REPORT, encoder .unmappableCharacterAction()); @@ -951,6 +1277,18 @@ public class CharsetEncoderTest extends TestCase { .unmappableCharacterAction()); } +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "replaceWith", + methodArgs = {byte[].class} + ), @TestTarget( + methodName = "replacement", + methodArgs = {} + ) + }) public void testReplacement() { try { encoder.replaceWith(null); diff --git a/nio_char/src/test/java/tests/api/java/nio/charset/CharsetProviderTest.java b/nio_char/src/test/java/tests/api/java/nio/charset/CharsetProviderTest.java index 74b56a9..e6b69bc 100644 --- a/nio_char/src/test/java/tests/api/java/nio/charset/CharsetProviderTest.java +++ b/nio_char/src/test/java/tests/api/java/nio/charset/CharsetProviderTest.java @@ -15,6 +15,11 @@ */ package tests.api.java.nio.charset; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestLevel; + import java.io.File; import java.io.FileOutputStream; import java.io.OutputStreamWriter; @@ -28,6 +33,7 @@ import junit.framework.TestCase; import tests.api.java.nio.charset.CharsetTest.MockCharset; import tests.api.java.nio.charset.CharsetTest.MockSecurityManager; +@TestTargetClass(CharsetProvider.class) /** * Test charset providers managed by Charset. */ @@ -91,7 +97,7 @@ public class CharsetProviderTest extends TestCase { * Test the method isSupported(String) with charset supported by some * providers (multiple). */ - public void testIsSupported_And_ForName_NormalProvider() throws Exception { + public void _testIsSupported_And_ForName_NormalProvider() throws Exception { try { assertFalse(Charset.isSupported("mockCharset10")); assertFalse(Charset.isSupported("mockCharset11")); @@ -159,6 +165,15 @@ public class CharsetProviderTest extends TestCase { * Test the method isSupported(String) when the configuration file contains * a non-existing class name. */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "Test for Charset.isSupported", + targets = { + @TestTarget( + methodName = "charsets", + methodArgs = {} + ) + }) public void testIsSupported_NonExistingClass() throws Exception { try { StringBuffer sb = new StringBuffer(); @@ -178,7 +193,7 @@ public class CharsetProviderTest extends TestCase { * Test the method isSupported(String) when the configuration file contains * a non-CharsetProvider class name. */ - public void testIsSupported_NotCharsetProviderClass() throws Exception { + public void _testIsSupported_NotCharsetProviderClass() throws Exception { try { StringBuffer sb = new StringBuffer(); sb.append("java.lang.String\r"); @@ -197,7 +212,7 @@ public class CharsetProviderTest extends TestCase { * Test the method isSupported(String) with insufficient privilege to use * charset provider. */ - public void testIsSupported_InsufficientPrivilege() throws Exception { + public void _testIsSupported_InsufficientPrivilege() throws Exception { SecurityManager oldMan = System.getSecurityManager(); System.setSecurityManager(new MockSecurityManager()); try { @@ -225,6 +240,15 @@ public class CharsetProviderTest extends TestCase { * Test the method forName(String) when the charset provider supports a * built-in charset. */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Test for Charset.isSupported", + targets = { + @TestTarget( + methodName = "charsets", + methodArgs = {} + ) + }) public void testForName_DuplicateWithBuiltInCharset() throws Exception { try { StringBuffer sb = new StringBuffer(); @@ -243,7 +267,7 @@ public class CharsetProviderTest extends TestCase { * Test the method forName(String) when the configuration file contains a * non-existing class name. */ - public void testForName_NonExistingClass() throws Exception { + public void _testForName_NonExistingClass() throws Exception { try { StringBuffer sb = new StringBuffer(); sb.append("impossible\r"); @@ -262,7 +286,7 @@ public class CharsetProviderTest extends TestCase { * Test the method forName(String) when the configuration file contains a * non-CharsetProvider class name. */ - public void testForName_NotCharsetProviderClass() throws Exception { + public void _testForName_NotCharsetProviderClass() throws Exception { try { StringBuffer sb = new StringBuffer(); sb.append("java.lang.String\r"); @@ -281,7 +305,7 @@ public class CharsetProviderTest extends TestCase { * Test the method availableCharsets() with charset supported by some * providers (multiple). */ - public void testAvailableCharsets_NormalProvider() throws Exception { + public void _testAvailableCharsets_NormalProvider() throws Exception { try { assertFalse(Charset.availableCharsets() .containsKey("mockCharset10")); @@ -340,6 +364,15 @@ public class CharsetProviderTest extends TestCase { * Test the method availableCharsets(String) when the configuration file * contains a non-existing class name. */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Test for Charset.isSupported", + targets = { + @TestTarget( + methodName = "charsets", + methodArgs = {} + ) + }) public void testAvailableCharsets_NonExistingClass() throws Exception { try { StringBuffer sb = new StringBuffer(); @@ -359,7 +392,7 @@ public class CharsetProviderTest extends TestCase { * Test the method availableCharsets(String) when the configuration file * contains a non-CharsetProvider class name. */ - public void testAvailableCharsets_NotCharsetProviderClass() + public void _testAvailableCharsets_NotCharsetProviderClass() throws Exception { try { StringBuffer sb = new StringBuffer(); @@ -379,6 +412,15 @@ public class CharsetProviderTest extends TestCase { * Test the method availableCharsets(String) when the configuration file * contains an illegal string. */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Test for Charset.isSupported", + targets = { + @TestTarget( + methodName = "charsets", + methodArgs = {} + ) + }) public void testAvailableCharsets_IllegalString() throws Exception { try { StringBuffer sb = new StringBuffer(); diff --git a/nio_char/src/test/java/tests/api/java/nio/charset/CharsetTest.java b/nio_char/src/test/java/tests/api/java/nio/charset/CharsetTest.java index daf24a5..22d2f8b 100644 --- a/nio_char/src/test/java/tests/api/java/nio/charset/CharsetTest.java +++ b/nio_char/src/test/java/tests/api/java/nio/charset/CharsetTest.java @@ -16,6 +16,11 @@ package tests.api.java.nio.charset; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestLevel; + import java.nio.ByteBuffer; import java.nio.CharBuffer; import java.nio.charset.Charset; @@ -33,6 +38,7 @@ import java.util.Vector; import junit.framework.TestCase; +@TestTargetClass(Charset.class) /** * Test class java.nio.Charset. */ @@ -61,6 +67,21 @@ public class CharsetTest extends TestCase { /* * Test the required 6 charsets are supported. */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "Test is OK for availableCharsets. For forName & isSupported only functionality tested.", + targets = { + @TestTarget( + methodName = "isSupported", + methodArgs = {java.lang.String.class} + ), @TestTarget( + methodName = "forName", + methodArgs = {java.lang.String.class} + ), @TestTarget( + methodName = "availableCharsets", + methodArgs = {} + ) + }) public void testRequiredCharsetSupported() { assertTrue(Charset.isSupported("US-ASCII")); assertTrue(Charset.isSupported("ASCII")); @@ -98,6 +119,15 @@ public class CharsetTest extends TestCase { /* * Test the method isSupported(String) with null. */ +@TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "IllegalArgumentException checked.", + targets = { + @TestTarget( + methodName = "isSupported", + methodArgs = {java.lang.String.class} + ) + }) public void testIsSupported_Null() { try { Charset.isSupported(null); @@ -111,6 +141,15 @@ public class CharsetTest extends TestCase { * Test the method isSupported(String) with empty string. * */ +@TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "check test on target vm and fix, now it is dummy", + targets = { + @TestTarget( + methodName = "isSupported", + methodArgs = {java.lang.String.class} + ) + }) public void testIsSupported_EmptyString() { try { Charset.isSupported(""); @@ -124,6 +163,15 @@ public class CharsetTest extends TestCase { * Test the method isSupported(String) with a string starting with ".". * */ +@TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "isSupported", + methodArgs = {java.lang.String.class} + ) + }) public void testIsSupported_InvalidInitialCharacter() { try { Charset.isSupported(".char"); @@ -135,6 +183,15 @@ public class CharsetTest extends TestCase { /* * Test the method isSupported(String) with illegal charset name. */ +@TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "IllegalArgumentException checked.", + targets = { + @TestTarget( + methodName = "isSupported", + methodArgs = {java.lang.String.class} + ) + }) public void testIsSupported_IllegalName() { try { Charset.isSupported(" ///#$$"); @@ -147,6 +204,15 @@ public class CharsetTest extends TestCase { /* * Test the method isSupported(String) with not supported charset name. */ +@TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "isSupported", + methodArgs = {java.lang.String.class} + ) + }) public void testIsSupported_NotSupported() { assertFalse(Charset.isSupported("impossible")); } @@ -154,6 +220,15 @@ public class CharsetTest extends TestCase { /* * Test the method forName(String) with null. */ +@TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "forName", + methodArgs = {java.lang.String.class} + ) + }) public void testForName_Null() { try { Charset.forName(null); @@ -166,6 +241,15 @@ public class CharsetTest extends TestCase { /* * Test the method forName(String) with empty string. */ +@TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "forName", + methodArgs = {java.lang.String.class} + ) + }) public void testForName_EmptyString() { try { Charset.forName(""); @@ -178,6 +262,15 @@ public class CharsetTest extends TestCase { /* * Test the method forName(String) with a string starting with ".". */ +@TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "forName", + methodArgs = {java.lang.String.class} + ) + }) public void testForName_InvalidInitialCharacter() { try { Charset.forName(".char"); @@ -190,6 +283,15 @@ public class CharsetTest extends TestCase { /* * Test the method forName(String) with illegal charset name. */ +@TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "forName", + methodArgs = {java.lang.String.class} + ) + }) public void testForName_IllegalName() { try { Charset.forName(" ///#$$"); @@ -202,6 +304,15 @@ public class CharsetTest extends TestCase { /* * Test the method forName(String) with not supported charset name. */ +@TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "forName", + methodArgs = {java.lang.String.class} + ) + }) public void testForName_NotSupported() { try { Charset.forName("impossible"); @@ -214,6 +325,24 @@ public class CharsetTest extends TestCase { /* * Test the constructor with normal parameter values. */ +@TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "name", + methodArgs = {} + ), @TestTarget( + methodName = "displayName", + methodArgs = {} + ), @TestTarget( + methodName = "aliases", + methodArgs = {} + ), @TestTarget( + methodName = "Charset", + methodArgs = {java.lang.String.class, java.lang.String[].class} + ) + }) public void testConstructor_Normal() { final String mockName = "mockChar1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.:-_"; MockCharset c = new MockCharset(mockName, new String[] { "mock" }); @@ -228,6 +357,15 @@ public class CharsetTest extends TestCase { * Test the constructor with empty canonical name. * */ +@TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "check test on target vm and fix, now it is dummy", + targets = { + @TestTarget( + methodName = "Charset", + methodArgs = {java.lang.String.class, java.lang.String[].class} + ) + }) public void testConstructor_EmptyCanonicalName() { try { new MockCharset("", new String[0]); @@ -242,6 +380,15 @@ public class CharsetTest extends TestCase { * digit nor a letter. * */ +@TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "Charset", + methodArgs = {java.lang.String.class, java.lang.String[].class} + ) + }) public void testConstructor_IllegalCanonicalName_Initial() { try { new MockCharset("-123", new String[] { "mock" }); @@ -254,6 +401,15 @@ public class CharsetTest extends TestCase { * Test the constructor with illegal canonical name, illegal character in * the middle. */ +@TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "Charset", + methodArgs = {java.lang.String.class, java.lang.String[].class} + ) + }) public void testConstructor_IllegalCanonicalName_Middle() { try { new MockCharset("1%%23", new String[] { "mock" }); @@ -272,6 +428,15 @@ public class CharsetTest extends TestCase { /* * Test the constructor with null canonical name. */ +@TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "Charset", + methodArgs = {java.lang.String.class, java.lang.String[].class} + ) + }) public void testConstructor_NullCanonicalName() { try { MockCharset c = new MockCharset(null, new String[] { "mock" }); @@ -284,6 +449,27 @@ public class CharsetTest extends TestCase { /* * Test the constructor with null aliases. */ +@TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "Charset", + methodArgs = {java.lang.String.class, java.lang.String[].class} + ), @TestTarget( + methodName = "name", + methodArgs = {} + ), @TestTarget( + methodName = "displayName", + methodArgs = {} + ), @TestTarget( + methodName = "displayName", + methodArgs = {java.util.Locale.class} + ), @TestTarget( + methodName = "aliases", + methodArgs = {} + ) + }) public void testConstructor_NullAliases() { MockCharset c = new MockCharset("mockChar", null); assertEquals("mockChar", c.name()); @@ -295,6 +481,15 @@ public class CharsetTest extends TestCase { /* * Test the constructor with a null aliases. */ +@TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "Charset", + methodArgs = {java.lang.String.class, java.lang.String[].class} + ) + }) public void testConstructor_NullAliase() { try { new MockCharset("mockChar", new String[] { "mock", null }); @@ -307,6 +502,27 @@ public class CharsetTest extends TestCase { /* * Test the constructor with no aliases. */ +@TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "Charset", + methodArgs = {java.lang.String.class, java.lang.String[].class} + ), @TestTarget( + methodName = "name", + methodArgs = {} + ), @TestTarget( + methodName = "displayName", + methodArgs = {} + ), @TestTarget( + methodName = "displayName", + methodArgs = {java.util.Locale.class} + ), @TestTarget( + methodName = "aliases", + methodArgs = {} + ) + }) public void testConstructor_NoAliases() { MockCharset c = new MockCharset("mockChar", new String[0]); assertEquals("mockChar", c.name()); @@ -319,6 +535,15 @@ public class CharsetTest extends TestCase { * Test the constructor with empty aliases. * */ +@TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "Charset", + methodArgs = {java.lang.String.class, java.lang.String[].class} + ) + }) public void testConstructor_EmptyAliases() { try { new MockCharset("mockChar", new String[] { "" }); @@ -333,6 +558,15 @@ public class CharsetTest extends TestCase { * nor a letter. * */ +@TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "Charset", + methodArgs = {java.lang.String.class, java.lang.String[].class} + ) + }) public void testConstructor_IllegalAliases_Initial() { try { new MockCharset("mockChar", new String[] { "mock", "-123" }); @@ -345,6 +579,15 @@ public class CharsetTest extends TestCase { * Test the constructor with illegal aliase, illegal character in the * middle. */ +@TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "Charset", + methodArgs = {java.lang.String.class, java.lang.String[].class} + ) + }) public void testConstructor_IllegalAliases_Middle() { try { new MockCharset("mockChar", new String[] { "mock", "22##ab" }); @@ -364,6 +607,15 @@ public class CharsetTest extends TestCase { * Test the method aliases() with multiple aliases. Most conditions have * been tested in the testcases for the constructors. */ +@TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "aliases", + methodArgs = {} + ) + }) public void testAliases_Multiple() { final String mockName = "mockChar1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.:-_"; MockCharset c = new MockCharset("mockChar", new String[] { "mock", @@ -386,6 +638,15 @@ public class CharsetTest extends TestCase { * Test the method aliases() with duplicate aliases, one same with its * canonical name. */ +@TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "aliases", + methodArgs = {} + ) + }) public void testAliases_Duplicate() { final String mockName = "mockChar1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.:-_"; MockCharset c = new MockCharset("mockChar", new String[] { "mockChar", @@ -401,6 +662,15 @@ public class CharsetTest extends TestCase { /* * Test the method canEncode(). Test the default return value. */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "canEncode", + methodArgs = {} + ) + }) public void testCanEncode() { MockCharset c = new MockCharset("mock", null); assertTrue(c.canEncode()); @@ -409,6 +679,15 @@ public class CharsetTest extends TestCase { /* * Test the method isRegistered(). Test the default return value. */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "isRegistered", + methodArgs = {} + ) + }) public void testIsRegistered() { MockCharset c = new MockCharset("mock", null); assertTrue(c.isRegistered()); @@ -417,6 +696,15 @@ public class CharsetTest extends TestCase { /* * The name() method has been tested by the testcases for the constructor. */ +@TestInfo( + level = TestLevel.TODO, + purpose = "Test is empty", + targets = { + @TestTarget( + methodName = "name", + methodArgs = {} + ) + }) public void testName() { // already covered by testConstructor_XXX series } @@ -425,6 +713,15 @@ public class CharsetTest extends TestCase { * The displayName() method have been tested by the testcases for the * constructor. */ +@TestInfo( + level = TestLevel.TODO, + purpose = "Test is empty", + targets = { + @TestTarget( + methodName = "displayName", + methodArgs = {} + ) + }) public void testDisplayName() { // already covered by testConstructor_XXX series } @@ -432,6 +729,15 @@ public class CharsetTest extends TestCase { /* * Test displayName(Locale) with null. */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "displayName", + methodArgs = {java.util.Locale.class} + ) + }) public void testDisplayName_Locale_Null() { MockCharset c = new MockCharset("mock", null); assertEquals("mock", c.displayName(null)); @@ -440,6 +746,15 @@ public class CharsetTest extends TestCase { /* * Test the method compareTo(Object) with normal conditions. */ +@TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "compareTo", + methodArgs = {java.nio.charset.Charset.class} + ) + }) public void testCompareTo_Normal() { MockCharset c1 = new MockCharset("mock", null); assertEquals(0, c1.compareTo(c1)); @@ -475,6 +790,15 @@ public class CharsetTest extends TestCase { /* * Test the method compareTo(Object) with null param. */ +@TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "compareTo", + methodArgs = {java.lang.Object.class} + ) + }) public void testCompareTo_Null() { MockCharset c1 = new MockCharset("mock", null); try { @@ -488,6 +812,15 @@ public class CharsetTest extends TestCase { /* * Test the method compareTo(Object) with another kind of charset object. */ +@TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "compareTo", + methodArgs = {java.nio.charset.Charset.class} + ) + }) public void testCompareTo_DiffCharsetClass() { MockCharset c1 = new MockCharset("mock", null); MockCharset2 c2 = new MockCharset2("Mock", new String[] { "myname" }); @@ -498,6 +831,15 @@ public class CharsetTest extends TestCase { /* * Test the method equals(Object) with null param. */ +@TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "equals", + methodArgs = {java.lang.Object.class} + ) + }) public void testEquals_Normal() { MockCharset c1 = new MockCharset("mock", null); MockCharset2 c2 = new MockCharset2("mock", null); @@ -512,6 +854,15 @@ public class CharsetTest extends TestCase { /* * Test the method equals(Object) with normal conditions. */ +@TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "equals", + methodArgs = {java.lang.Object.class} + ) + }) public void testEquals_Null() { MockCharset c1 = new MockCharset("mock", null); assertFalse(c1.equals(null)); @@ -520,6 +871,15 @@ public class CharsetTest extends TestCase { /* * Test the method equals(Object) with another kind of charset object. */ +@TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "equals", + methodArgs = {java.lang.Object.class} + ) + }) public void testEquals_NonCharsetObject() { MockCharset c1 = new MockCharset("mock", null); assertFalse(c1.equals("test")); @@ -528,6 +888,15 @@ public class CharsetTest extends TestCase { /* * Test the method equals(Object) with another kind of charset object. */ +@TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "equals", + methodArgs = {java.lang.Object.class} + ) + }) public void testEquals_DiffCharsetClass() { MockCharset c1 = new MockCharset("mock", null); MockCharset2 c2 = new MockCharset2("mock", null); @@ -538,6 +907,15 @@ public class CharsetTest extends TestCase { /* * Test the method hashCode(). */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "hashCode", + methodArgs = {} + ) + }) public void testHashCode_DiffCharsetClass() { MockCharset c1 = new MockCharset("mock", null); assertEquals(c1.hashCode(), "mock".hashCode()); @@ -551,6 +929,15 @@ public class CharsetTest extends TestCase { /* * Test the method encode(CharBuffer) under normal condition. */ +@TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "encode", + methodArgs = {java.nio.CharBuffer.class} + ) + }) public void testEncode_CharBuffer_Normal() throws Exception { MockCharset c1 = new MockCharset("testEncode_CharBuffer_Normal_mock", null); ByteBuffer bb = c1.encode(CharBuffer.wrap("abcdefg")); @@ -562,6 +949,18 @@ public class CharsetTest extends TestCase { /* * Test the method encode(CharBuffer) with an unmappable char. */ +@TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "encode", + methodArgs = {java.nio.CharBuffer.class} + ), @TestTarget( + methodName = "newEncoder", + methodArgs = {} + ) + }) public void testEncode_CharBuffer_Unmappable() throws Exception { Charset c1 = Charset.forName("iso8859-1"); ByteBuffer bb = c1.encode(CharBuffer.wrap("abcd\u5D14efg")); @@ -573,6 +972,15 @@ public class CharsetTest extends TestCase { /* * Test the method encode(CharBuffer) with null CharBuffer. */ +@TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "encode", + methodArgs = {java.nio.CharBuffer.class} + ) + }) public void testEncode_CharBuffer_NullCharBuffer() { MockCharset c = new MockCharset("mock", null); try { @@ -586,6 +994,15 @@ public class CharsetTest extends TestCase { /* * Test the method encode(CharBuffer) with null encoder. */ +@TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "encode", + methodArgs = {java.nio.CharBuffer.class} + ) + }) public void testEncode_CharBuffer_NullEncoder() { MockCharset2 c = new MockCharset2("mock2", null); try { @@ -599,6 +1016,15 @@ public class CharsetTest extends TestCase { /* * Test the method encode(String) under normal condition. */ +@TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "encode", + methodArgs = {java.nio.CharBuffer.class} + ) + }) public void testEncode_String_Normal() throws Exception { MockCharset c1 = new MockCharset("testEncode_String_Normal_mock", null); ByteBuffer bb = c1.encode("abcdefg"); @@ -610,6 +1036,18 @@ public class CharsetTest extends TestCase { /* * Test the method encode(String) with an unmappable char. */ +@TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "encode", + methodArgs = {java.nio.CharBuffer.class} + ), @TestTarget( + methodName = "newEncoder", + methodArgs = {} + ) + }) public void testEncode_String_Unmappable() throws Exception { Charset c1 = Charset.forName("iso8859-1"); ByteBuffer bb = c1.encode("abcd\u5D14efg"); @@ -621,6 +1059,15 @@ public class CharsetTest extends TestCase { /* * Test the method encode(String) with null CharBuffer. */ +@TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "encode", + methodArgs = {java.nio.CharBuffer.class} + ) + }) public void testEncode_String_NullString() { MockCharset c = new MockCharset("mock", null); try { @@ -634,6 +1081,15 @@ public class CharsetTest extends TestCase { /* * Test the method encode(String) with null encoder. */ +@TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "encode", + methodArgs = {java.nio.CharBuffer.class} + ) + }) public void testEncode_String_NullEncoder() { MockCharset2 c = new MockCharset2("mock2", null); @@ -648,6 +1104,15 @@ public class CharsetTest extends TestCase { /* * Test the method decode(ByteBuffer) under normal condition. */ +@TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "decode", + methodArgs = {java.nio.ByteBuffer.class} + ) + }) public void testDecode_Normal() throws Exception { MockCharset c1 = new MockCharset("mock", null); CharBuffer cb = c1.decode(ByteBuffer.wrap("abcdefg" @@ -660,6 +1125,15 @@ public class CharsetTest extends TestCase { /* * Test the method decode(ByteBuffer) with a malformed input. */ +@TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "decode", + methodArgs = {java.nio.ByteBuffer.class} + ) + }) public void testDecode_Malformed() throws Exception { Charset c1 = Charset.forName("iso8859-1"); CharBuffer cb = c1.decode(ByteBuffer.wrap("abcd\u5D14efg" @@ -672,6 +1146,15 @@ public class CharsetTest extends TestCase { /* * Test the method decode(ByteBuffer) with null CharBuffer. */ +@TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "decode", + methodArgs = {java.nio.ByteBuffer.class} + ) + }) public void testDecode_NullByteBuffer() { MockCharset c = new MockCharset("mock", null); try { @@ -685,6 +1168,15 @@ public class CharsetTest extends TestCase { /* * Test the method decode(ByteBuffer) with null encoder. */ +@TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "decode", + methodArgs = {java.nio.ByteBuffer.class} + ) + }) public void testDecode_NullDecoder() { MockCharset2 c = new MockCharset2("mock2", null); try { @@ -698,6 +1190,15 @@ public class CharsetTest extends TestCase { /* * Test the method toString(). */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "toString", + methodArgs = {} + ) + }) public void testToString() { MockCharset c1 = new MockCharset("mock", null); assertTrue(-1 != c1.toString().indexOf("mock")); @@ -706,7 +1207,16 @@ public class CharsetTest extends TestCase { /** * @tests java.nio.charset.Charset#availableCharsets() */ - public void test_availableCharsets() throws Exception { +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "availableCharsets", + methodArgs = {} + ) + }) + public void _test_availableCharsets() throws Exception { // regression test for Harmony-1051 ClassLoader originalClassLoader = Thread.currentThread() .getContextClassLoader(); @@ -723,7 +1233,16 @@ public class CharsetTest extends TestCase { /** * @tests java.nio.charset.Charset#availableCharsets() */ - public void test_forNameLString() throws Exception { +@TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "forName", + methodArgs = {java.lang.String.class} + ) + }) + public void _test_forNameLString() throws Exception { // regression test for Harmony-1051 ClassLoader originalClassLoader = Thread.currentThread() .getContextClassLoader(); diff --git a/nio_char/src/test/java/tests/api/java/nio/charset/CoderResultTest.java b/nio_char/src/test/java/tests/api/java/nio/charset/CoderResultTest.java index d362a57..1b4a92d 100644 --- a/nio_char/src/test/java/tests/api/java/nio/charset/CoderResultTest.java +++ b/nio_char/src/test/java/tests/api/java/nio/charset/CoderResultTest.java @@ -16,6 +16,11 @@ package tests.api.java.nio.charset; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestLevel; + import java.nio.BufferOverflowException; import java.nio.BufferUnderflowException; import java.nio.charset.CoderResult; @@ -23,7 +28,7 @@ import java.nio.charset.MalformedInputException; import java.nio.charset.UnmappableCharacterException; import junit.framework.TestCase; - +@TestTargetClass(CoderResult.class) /** * Test class java.nio.charset.CoderResult. */ @@ -46,6 +51,36 @@ public class CoderResultTest extends TestCase { /* * Test the constant OVERFLOW and UNDERFLOW. */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "isError", + methodArgs = {} + ), @TestTarget( + methodName = "isMalformed", + methodArgs = {} + ), @TestTarget( + methodName = "isOverflow", + methodArgs = {} + ), @TestTarget( + methodName = "isUnderflow", + methodArgs = {} + ), @TestTarget( + methodName = "isUnmappable", + methodArgs = {} + ), @TestTarget( + methodName = "length", + methodArgs = {} + ), @TestTarget( + methodName = "throwException", + methodArgs = {} + ), @TestTarget( + methodName = "toString", + methodArgs = {} + ) + }) public void testConstants() throws Exception { assertNotSame(CoderResult.OVERFLOW, CoderResult.UNDERFLOW); @@ -94,6 +129,21 @@ public class CoderResultTest extends TestCase { * Test method isError(). * */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "isError", + methodArgs = {} + ), @TestTarget( + methodName = "malformedForLength", + methodArgs = {int.class} + ), @TestTarget( + methodName = "unmappableForLength", + methodArgs = {int.class} + ) + }) public void testIsError() { assertFalse(CoderResult.UNDERFLOW.isError()); assertFalse(CoderResult.OVERFLOW.isError()); @@ -105,6 +155,21 @@ public class CoderResultTest extends TestCase { * Test method isMalformed(). * */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "isMalformed", + methodArgs = {} + ), @TestTarget( + methodName = "malformedForLength", + methodArgs = {int.class} + ), @TestTarget( + methodName = "unmappableForLength", + methodArgs = {int.class} + ) + }) public void testIsMalformed() { assertFalse(CoderResult.UNDERFLOW.isMalformed()); assertFalse(CoderResult.OVERFLOW.isMalformed()); @@ -116,6 +181,21 @@ public class CoderResultTest extends TestCase { * Test method isMalformed(). * */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "isUnmappable", + methodArgs = {} + ), @TestTarget( + methodName = "malformedForLength", + methodArgs = {int.class} + ), @TestTarget( + methodName = "unmappableForLength", + methodArgs = {int.class} + ) + }) public void testIsUnmappable() { assertFalse(CoderResult.UNDERFLOW.isUnmappable()); assertFalse(CoderResult.OVERFLOW.isUnmappable()); @@ -127,6 +207,21 @@ public class CoderResultTest extends TestCase { * Test method isOverflow(). * */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "isOverflow", + methodArgs = {} + ), @TestTarget( + methodName = "malformedForLength", + methodArgs = {int.class} + ), @TestTarget( + methodName = "unmappableForLength", + methodArgs = {int.class} + ) + }) public void testIsOverflow() { assertFalse(CoderResult.UNDERFLOW.isOverflow()); assertTrue(CoderResult.OVERFLOW.isOverflow()); @@ -138,6 +233,21 @@ public class CoderResultTest extends TestCase { * Test method isUnderflow(). * */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "isUnderflow", + methodArgs = {} + ), @TestTarget( + methodName = "malformedForLength", + methodArgs = {int.class} + ), @TestTarget( + methodName = "unmappableForLength", + methodArgs = {int.class} + ) + }) public void testIsUnderflow() { assertTrue(CoderResult.UNDERFLOW.isUnderflow()); assertFalse(CoderResult.OVERFLOW.isUnderflow()); @@ -149,6 +259,21 @@ public class CoderResultTest extends TestCase { * Test method length(). * */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "length", + methodArgs = {} + ), @TestTarget( + methodName = "malformedForLength", + methodArgs = {int.class} + ), @TestTarget( + methodName = "unmappableForLength", + methodArgs = {int.class} + ) + }) public void testLength() { try { CoderResult.UNDERFLOW.length(); @@ -171,6 +296,15 @@ public class CoderResultTest extends TestCase { * Test method malformedForLength(int). * */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "malformedForLength", + methodArgs = {int.class} + ) + }) public void testMalformedForLength() { assertNotNull(CoderResult.malformedForLength(Integer.MAX_VALUE)); assertNotNull(CoderResult.malformedForLength(1)); @@ -198,6 +332,15 @@ public class CoderResultTest extends TestCase { * Test method unmappableForLength(int). * */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "unmappableForLength", + methodArgs = {int.class} + ) + }) public void testUnmappableForLength() { assertNotNull(CoderResult.unmappableForLength(Integer.MAX_VALUE)); assertNotNull(CoderResult.unmappableForLength(1)); @@ -223,6 +366,21 @@ public class CoderResultTest extends TestCase { * Test method throwException(). * */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "throwException", + methodArgs = {} + ), @TestTarget( + methodName = "malformedForLength", + methodArgs = {int.class} + ), @TestTarget( + methodName = "unmappableForLength", + methodArgs = {int.class} + ) + }) public void testThrowException() throws Exception { try { CoderResult.OVERFLOW.throwException(); @@ -254,6 +412,21 @@ public class CoderResultTest extends TestCase { * Test method toString(). * */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "toString", + methodArgs = {} + ), @TestTarget( + methodName = "malformedForLength", + methodArgs = {int.class} + ), @TestTarget( + methodName = "unmappableForLength", + methodArgs = {int.class} + ) + }) public void testToString() throws Exception { assertTrue(CoderResult.OVERFLOW.toString().indexOf("OVERFLOW") != -1); assertTrue(CoderResult.UNDERFLOW.toString().indexOf("UNDERFLOW") != -1); diff --git a/nio_char/src/test/java/tests/api/java/nio/charset/CodingErrorActionTest.java b/nio_char/src/test/java/tests/api/java/nio/charset/CodingErrorActionTest.java index 1e23aef..5847fd1 100644 --- a/nio_char/src/test/java/tests/api/java/nio/charset/CodingErrorActionTest.java +++ b/nio_char/src/test/java/tests/api/java/nio/charset/CodingErrorActionTest.java @@ -16,10 +16,15 @@ package tests.api.java.nio.charset; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestLevel; + import java.nio.charset.CodingErrorAction; import junit.framework.TestCase; - +@TestTargetClass(CodingErrorAction.class) /** * Test class java.nio.charset.CodingErrorAction */ @@ -42,6 +47,15 @@ public class CodingErrorActionTest extends TestCase { /* * Test the constants. */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verify constant", + targets = { + @TestTarget( + methodName = "!Constants", + methodArgs = {} + ) + }) public void testIGNORE() { assertNotNull(CodingErrorAction.IGNORE); assertNotNull(CodingErrorAction.REPLACE); @@ -54,6 +68,15 @@ public class CodingErrorActionTest extends TestCase { /* * Test the method toString(). */ +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "Verify constant", + targets = { + @TestTarget( + methodName = "toString", + methodArgs = {} + ) + }) public void testToString() { assertTrue(CodingErrorAction.IGNORE.toString().indexOf("IGNORE") != -1); assertTrue(CodingErrorAction.REPLACE.toString().indexOf("REPLACE") != -1); diff --git a/nio_char/src/test/java/tests/api/java/nio/charset/GBCharsetDecoderTest.java b/nio_char/src/test/java/tests/api/java/nio/charset/GBCharsetDecoderTest.java index 855e85b..63f5398 100644 --- a/nio_char/src/test/java/tests/api/java/nio/charset/GBCharsetDecoderTest.java +++ b/nio_char/src/test/java/tests/api/java/nio/charset/GBCharsetDecoderTest.java @@ -16,10 +16,13 @@ package tests.api.java.nio.charset; +import dalvik.annotation.TestTargetClass; + import java.io.UnsupportedEncodingException; import java.nio.ByteBuffer; import java.nio.charset.Charset; +@TestTargetClass(java.nio.charset.CharsetDecoder.class) /** * test gb18030 decoder */ diff --git a/nio_char/src/test/java/tests/api/java/nio/charset/GBCharsetEncoderTest.java b/nio_char/src/test/java/tests/api/java/nio/charset/GBCharsetEncoderTest.java index 6890b0c..4e30997 100644 --- a/nio_char/src/test/java/tests/api/java/nio/charset/GBCharsetEncoderTest.java +++ b/nio_char/src/test/java/tests/api/java/nio/charset/GBCharsetEncoderTest.java @@ -16,10 +16,16 @@ package tests.api.java.nio.charset; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestLevel; + import java.nio.CharBuffer; import java.nio.charset.CharacterCodingException; import java.nio.charset.Charset; +@TestTargetClass(java.nio.charset.CharsetEncoder.class) /** * test case specific activity of gb18030 charset encoder */ @@ -43,6 +49,15 @@ public class GBCharsetEncoderTest extends CharsetEncoderTest { super.tearDown(); } +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "IllegalStateException checking missed.", + targets = { + @TestTarget( + methodName = "canEncode", + methodArgs = {char.class} + ) + }) public void testCanEncodechar() throws CharacterCodingException { // normal case for utfCS assertTrue(encoder.canEncode('\u0077')); @@ -55,6 +70,15 @@ public class GBCharsetEncoderTest extends CharsetEncoderTest { /* * Class under test for boolean canEncode(CharSequence) */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "IllegalStateException checking missed.", + targets = { + @TestTarget( + methodName = "canEncode", + methodArgs = {java.lang.CharSequence.class} + ) + }) public void testCanEncodeCharSequence() { assertTrue(encoder.canEncode("")); // surrogate char @@ -66,6 +90,18 @@ public class GBCharsetEncoderTest extends CharsetEncoderTest { assertFalse(encoder.canEncode("\ud800")); } +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "averageBytesPerChar", + methodArgs = {} + ), @TestTarget( + methodName = "maxBytesPerChar", + methodArgs = {} + ) + }) public void testSpecificDefaultValue() { // FIXME: different here! assertEquals(4.0, encoder.maxBytesPerChar(), 0.0); diff --git a/nio_char/src/test/java/tests/api/java/nio/charset/ISOCharsetDecoderTest.java b/nio_char/src/test/java/tests/api/java/nio/charset/ISOCharsetDecoderTest.java index f1104cd..efb2539 100644 --- a/nio_char/src/test/java/tests/api/java/nio/charset/ISOCharsetDecoderTest.java +++ b/nio_char/src/test/java/tests/api/java/nio/charset/ISOCharsetDecoderTest.java @@ -16,6 +16,8 @@ package tests.api.java.nio.charset; +import dalvik.annotation.TestTargetClass; + import java.io.UnsupportedEncodingException; import java.nio.ByteBuffer; import java.nio.charset.Charset; @@ -23,6 +25,7 @@ import java.nio.charset.Charset; /** * test ISO-8859-1 decoder */ +@TestTargetClass(java.nio.charset.CharsetDecoder.class) public class ISOCharsetDecoderTest extends CharsetDecoderTest { protected void setUp() throws Exception { diff --git a/nio_char/src/test/java/tests/api/java/nio/charset/ISOCharsetEncoderTest.java b/nio_char/src/test/java/tests/api/java/nio/charset/ISOCharsetEncoderTest.java index ea25929..af764c5 100644 --- a/nio_char/src/test/java/tests/api/java/nio/charset/ISOCharsetEncoderTest.java +++ b/nio_char/src/test/java/tests/api/java/nio/charset/ISOCharsetEncoderTest.java @@ -15,6 +15,11 @@ */ package tests.api.java.nio.charset; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestLevel; + import java.nio.ByteBuffer; import java.nio.CharBuffer; import java.nio.charset.CharacterCodingException; @@ -26,6 +31,7 @@ import java.nio.charset.UnmappableCharacterException; /** * test case specific activity of iso-8859-1 charset encoder */ +@TestTargetClass(java.nio.charset.CharsetEncoder.class) public class ISOCharsetEncoderTest extends CharsetEncoderTest { // charset for iso-8859-1 @@ -46,6 +52,15 @@ public class ISOCharsetEncoderTest extends CharsetEncoderTest { super.tearDown(); } +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "IllegalStateException checking missed.", + targets = { + @TestTarget( + methodName = "canEncode", + methodArgs = {java.lang.CharSequence.class} + ) + }) public void testCanEncodeCharSequence() { // normal case for isoCS assertTrue(encoder.canEncode("\u0077")); @@ -58,16 +73,49 @@ public class ISOCharsetEncoderTest extends CharsetEncoderTest { assertTrue(encoder.canEncode("")); } +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "Regression test. IllegalStateException checking missed.", + targets = { + @TestTarget( + methodName = "canEncode", + methodArgs = {char.class} + ), @TestTarget( + methodName = "canEncode", + methodArgs = {java.lang.CharSequence.class} + ) + }) public void testCanEncodeICUBug() { assertFalse(encoder.canEncode((char) '\ud800')); assertFalse(encoder.canEncode((String) "\ud800")); } +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "IllegalStateException checking missed.", + targets = { + @TestTarget( + methodName = "canEncode", + methodArgs = {char.class} + ) + }) public void testCanEncodechar() throws CharacterCodingException { assertTrue(encoder.canEncode('\u0077')); assertFalse(encoder.canEncode('\uc2a3')); } +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "averageBytesPerChar", + methodArgs = {} + ), @TestTarget( + methodName = "maxBytesPerChar", + methodArgs = {} + ) + }) public void testSpecificDefaultValue() { assertEquals(1, encoder.averageBytesPerChar(), 0.001); assertEquals(1, encoder.maxBytesPerChar(), 0.001); @@ -89,6 +137,21 @@ public class ISOCharsetEncoderTest extends CharsetEncoderTest { return null; } +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "Checks also: flush & encode, but not covers exceptions.", + targets = { + @TestTarget( + methodName = "onMalformedInput", + methodArgs = {java.nio.charset.CodingErrorAction.class} + ), @TestTarget( + methodName = "onUnmappableCharacter", + methodArgs = {java.nio.charset.CodingErrorAction.class} + ), @TestTarget( + methodName = "reset", + methodArgs = {} + ) + }) public void testMultiStepEncode() throws CharacterCodingException { encoder.onMalformedInput(CodingErrorAction.REPORT); encoder.onUnmappableCharacter(CodingErrorAction.REPORT); diff --git a/nio_char/src/test/java/tests/api/java/nio/charset/ISOCharsetTest.java b/nio_char/src/test/java/tests/api/java/nio/charset/ISOCharsetTest.java index 5c010b2..562adc3 100644 --- a/nio_char/src/test/java/tests/api/java/nio/charset/ISOCharsetTest.java +++ b/nio_char/src/test/java/tests/api/java/nio/charset/ISOCharsetTest.java @@ -16,9 +16,15 @@ package tests.api.java.nio.charset; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestLevel; + /** * Test ISO-8859-1. */ +@TestTargetClass(java.nio.charset.Charset.class) public class ISOCharsetTest extends AbstractCharsetTestCase { /** @@ -36,6 +42,15 @@ public class ISOCharsetTest extends AbstractCharsetTestCase { * * @see tests.api.java.nio.charset.ConcreteCharsetTest#testEncode_Normal() */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "Functional test, text source: AbstractCharsetTestCase.internalTestEncode. Exceptions checking missed.", + targets = { + @TestTarget( + methodName = "encode", + methodArgs = {java.lang.String.class} + ) + }) public void testEncode_Normal() { String input = "ab\u5D14\u654F"; byte[] output = new byte[] { 97, 98, @@ -49,6 +64,15 @@ public class ISOCharsetTest extends AbstractCharsetTestCase { * * @see tests.api.java.nio.charset.ConcreteCharsetTest#testDecode_Normal() */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "Functional test, text source: AbstractCharsetTestCase.internalTestDecode. Exceptions checking missed.", + targets = { + @TestTarget( + methodName = "decode", + methodArgs = {java.nio.ByteBuffer.class} + ) + }) public void testDecode_Normal() { byte[] input = new byte[] { 97, 98, 63, 63 }; char[] output = "ab??".toCharArray(); diff --git a/nio_char/src/test/java/tests/api/java/nio/charset/UTF16BECharsetDecoderTest.java b/nio_char/src/test/java/tests/api/java/nio/charset/UTF16BECharsetDecoderTest.java index 9e2b66d..0a43e42 100644 --- a/nio_char/src/test/java/tests/api/java/nio/charset/UTF16BECharsetDecoderTest.java +++ b/nio_char/src/test/java/tests/api/java/nio/charset/UTF16BECharsetDecoderTest.java @@ -16,6 +16,8 @@ package tests.api.java.nio.charset; +import dalvik.annotation.TestTargetClass; + import java.io.UnsupportedEncodingException; import java.nio.ByteBuffer; import java.nio.charset.Charset; @@ -23,6 +25,8 @@ import java.nio.charset.Charset; /** * */ + +@TestTargetClass(java.nio.charset.CharsetDecoder.class) public class UTF16BECharsetDecoderTest extends CharsetDecoderTest { protected void setUp() throws Exception { diff --git a/nio_char/src/test/java/tests/api/java/nio/charset/UTF16BECharsetEncoderTest.java b/nio_char/src/test/java/tests/api/java/nio/charset/UTF16BECharsetEncoderTest.java index 194b3b3..4f05c46 100644 --- a/nio_char/src/test/java/tests/api/java/nio/charset/UTF16BECharsetEncoderTest.java +++ b/nio_char/src/test/java/tests/api/java/nio/charset/UTF16BECharsetEncoderTest.java @@ -16,6 +16,11 @@ package tests.api.java.nio.charset; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestLevel; + import java.nio.CharBuffer; import java.nio.charset.CharacterCodingException; import java.nio.charset.Charset; @@ -23,6 +28,7 @@ import java.nio.charset.Charset; /** * TODO type def */ +@TestTargetClass(java.nio.charset.CharsetEncoder.class) public class UTF16BECharsetEncoderTest extends CharsetEncoderTest { // charset for utf-16be @@ -50,10 +56,28 @@ public class UTF16BECharsetEncoderTest extends CharsetEncoderTest { super.tearDown(); } +@TestInfo( + level = TestLevel.TODO, + purpose = "Empty test.", + targets = { + @TestTarget( + methodName = "CharsetEncoder", + methodArgs = {java.nio.charset.Charset.class, float.class, float.class} + ) + }) public void testCharsetEncoderCharsetfloatfloat() { // this constructor is invalid for UTF16LE CharsetEncoder } +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "IllegalStateException checking missed.", + targets = { + @TestTarget( + methodName = "canEncode", + methodArgs = {char.class} + ) + }) public void testCanEncodechar() throws CharacterCodingException { // normal case for utfCS assertTrue(encoder.canEncode('\u0077')); @@ -64,6 +88,15 @@ public class UTF16BECharsetEncoderTest extends CharsetEncoderTest { } +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "IllegalStateException checking missed.", + targets = { + @TestTarget( + methodName = "canEncode", + methodArgs = {java.lang.CharSequence.class} + ) + }) public void testCanEncodeCharSequence() { // normal case for utfCS assertTrue(encoder.canEncode("\u0077")); @@ -82,10 +115,28 @@ public class UTF16BECharsetEncoderTest extends CharsetEncoderTest { assertFalse(encoder.canEncode("\ud800\udb00")); } +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "Regression test. IllegalStateException checking missed.", + targets = { + @TestTarget( + methodName = "canEncode", + methodArgs = {java.lang.CharSequence.class} + ) + }) public void testCanEncodeICUBug() { assertFalse(encoder.canEncode("\ud800")); } +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "maxBytesPerChar", + methodArgs = {} + ) + }) public void testSpecificDefaultValue() { // ??? TODO NIO adapt to the actually used UTF16BE charset Encoder // assertEquals(2, encoder.averageBytesPerChar(), 0.001); @@ -104,6 +155,15 @@ public class UTF16BECharsetEncoderTest extends CharsetEncoderTest { return null; } +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "isLegalReplacement", + methodArgs = {byte[].class} + ) + }) public void testIsLegalReplacementEmptyArray() { assertTrue(encoder.isLegalReplacement(new byte[0])); } diff --git a/nio_char/src/test/java/tests/api/java/nio/charset/UTF16BECharsetTest.java b/nio_char/src/test/java/tests/api/java/nio/charset/UTF16BECharsetTest.java index 754afa3..353a08b 100644 --- a/nio_char/src/test/java/tests/api/java/nio/charset/UTF16BECharsetTest.java +++ b/nio_char/src/test/java/tests/api/java/nio/charset/UTF16BECharsetTest.java @@ -16,9 +16,15 @@ package tests.api.java.nio.charset; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestLevel; + /** * Test UTF-16BE. */ +@TestTargetClass(java.nio.charset.Charset.class) public class UTF16BECharsetTest extends AbstractCharsetTestCase { /** @@ -34,6 +40,15 @@ public class UTF16BECharsetTest extends AbstractCharsetTestCase { * * @see tests.api.java.nio.charset.ConcreteCharsetTest#testEncode_Normal() */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "Functional test, text source: AbstractCharsetTestCase.internalTestEncode. Exceptions checking missed.", + targets = { + @TestTarget( + methodName = "encode", + methodArgs = {java.lang.String.class} + ) + }) public void testEncode_Normal() { String input = "ab\u5D14\u654F"; byte[] output = new byte[] { 0, 97, 0, 98, 93, 20, 101, 79 }; @@ -45,6 +60,15 @@ public class UTF16BECharsetTest extends AbstractCharsetTestCase { * * @see tests.api.java.nio.charset.ConcreteCharsetTest#testDecode_Normal() */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "Functional test, text source: AbstractCharsetTestCase.internalTestDecode. Exceptions checking missed.", + targets = { + @TestTarget( + methodName = "decode", + methodArgs = {java.nio.ByteBuffer.class} + ) + }) public void testDecode_Normal() { byte[] input = new byte[] { 0, 97, 0, 98, 93, 20, 101, 79 }; char[] output = "ab\u5D14\u654F".toCharArray(); diff --git a/nio_char/src/test/java/tests/api/java/nio/charset/UTF16CharsetDecoderTest.java b/nio_char/src/test/java/tests/api/java/nio/charset/UTF16CharsetDecoderTest.java index fa1d5ec..17fbfc5 100644 --- a/nio_char/src/test/java/tests/api/java/nio/charset/UTF16CharsetDecoderTest.java +++ b/nio_char/src/test/java/tests/api/java/nio/charset/UTF16CharsetDecoderTest.java @@ -16,6 +16,11 @@ package tests.api.java.nio.charset; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestLevel; + import java.io.UnsupportedEncodingException; import java.nio.ByteBuffer; import java.nio.CharBuffer; @@ -27,6 +32,7 @@ import java.nio.charset.CodingErrorAction; /** * */ +@TestTargetClass(java.nio.charset.CharsetDecoder.class) public class UTF16CharsetDecoderTest extends CharsetDecoderTest { boolean bigEndian = true; @@ -68,6 +74,15 @@ public class UTF16CharsetDecoderTest extends CharsetDecoderTest { } } +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "Exceptions checking missed.", + targets = { + @TestTarget( + methodName = "decode", + methodArgs = {java.nio.ByteBuffer.class, java.nio.CharBuffer.class, boolean.class} + ) + }) public void testMultiStepDecode() throws CharacterCodingException { if (!cs.name().equals("mock")) { decoder.onMalformedInput(CodingErrorAction.REPORT); @@ -112,6 +127,18 @@ public class UTF16CharsetDecoderTest extends CharsetDecoderTest { } } +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "Implementation in CharsetDecoderTest.implTestDecodeByteBufferCharBufferboolean & CharsetDecoderTest.implTestDecodeByteBuffer. Exceptions cheching missed.", + targets = { + @TestTarget( + methodName = "decode", + methodArgs = {java.nio.ByteBuffer.class} + ), @TestTarget( + methodName = "decode", + methodArgs = {java.nio.ByteBuffer.class, java.nio.CharBuffer.class, boolean.class} + ) + }) public void testLittleEndian() throws CharacterCodingException, UnsupportedEncodingException { bigEndian = false; diff --git a/nio_char/src/test/java/tests/api/java/nio/charset/UTF16CharsetEncoderTest.java b/nio_char/src/test/java/tests/api/java/nio/charset/UTF16CharsetEncoderTest.java index bdc505d..e0b4b7d 100644 --- a/nio_char/src/test/java/tests/api/java/nio/charset/UTF16CharsetEncoderTest.java +++ b/nio_char/src/test/java/tests/api/java/nio/charset/UTF16CharsetEncoderTest.java @@ -16,6 +16,11 @@ package tests.api.java.nio.charset; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestLevel; + import java.nio.ByteBuffer; import java.nio.CharBuffer; import java.nio.charset.CharacterCodingException; @@ -25,6 +30,7 @@ import java.nio.charset.CharsetDecoder; /** * TODO type def */ +@TestTargetClass(java.nio.charset.CharsetEncoder.class) public class UTF16CharsetEncoderTest extends CharsetEncoderTest { // charset for utf-16 @@ -54,10 +60,28 @@ public class UTF16CharsetEncoderTest extends CharsetEncoderTest { super.tearDown(); } +@TestInfo( + level = TestLevel.TODO, + purpose = "Test is empty", + targets = { + @TestTarget( + methodName = "CharsetEncoder", + methodArgs = {java.nio.charset.Charset.class, float.class, float.class} + ) + }) public void testCharsetEncoderCharsetfloatfloat() { // this constructor is invalid for UTF16LE CharsetEncoder } +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "IllegalStateException checking missed.", + targets = { + @TestTarget( + methodName = "canEncode", + methodArgs = {char.class} + ) + }) public void testCanEncodechar() throws CharacterCodingException { // normal case for utfCS assertTrue(encoder.canEncode('\u0077')); @@ -67,6 +91,15 @@ public class UTF16CharsetEncoderTest extends CharsetEncoderTest { assertTrue(encoder.canEncode('\uc2c0')); } +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "IllegalStateException checking missed.", + targets = { + @TestTarget( + methodName = "canEncode", + methodArgs = {java.lang.CharSequence.class} + ) + }) public void testCanEncodeCharSequence() { // normal case for utfCS assertTrue(encoder.canEncode("\u0077")); @@ -85,11 +118,35 @@ public class UTF16CharsetEncoderTest extends CharsetEncoderTest { assertFalse(encoder.canEncode("\ud800\udb00")); } +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "IllegalStateException checking missed.", + targets = { + @TestTarget( + methodName = "canEncode", + methodArgs = {char.class} + ), @TestTarget( + methodName = "canEncode", + methodArgs = {java.lang.CharSequence.class} + ) + }) public void testCanEncodeICUBug() { assertFalse(encoder.canEncode('\ud800')); assertFalse(encoder.canEncode("\ud800")); } +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "averageBytesPerChar", + methodArgs = {} + ), @TestTarget( + methodName = "maxBytesPerChar", + methodArgs = {} + ) + }) public void testSpecificDefaultValue() { assertEquals(encoder.averageBytesPerChar(), 2, 0.001); // assertEquals(4, encoder.maxBytesPerChar()); @@ -109,6 +166,15 @@ public class UTF16CharsetEncoderTest extends CharsetEncoderTest { return null; } +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "isLegalReplacement", + methodArgs = {byte[].class} + ) + }) public void testIsLegalReplacementEmptyArray() { assertTrue(encoder.isLegalReplacement(new byte[0])); } diff --git a/nio_char/src/test/java/tests/api/java/nio/charset/UTF16CharsetTest.java b/nio_char/src/test/java/tests/api/java/nio/charset/UTF16CharsetTest.java index e77be5e..725e43a 100644 --- a/nio_char/src/test/java/tests/api/java/nio/charset/UTF16CharsetTest.java +++ b/nio_char/src/test/java/tests/api/java/nio/charset/UTF16CharsetTest.java @@ -16,9 +16,15 @@ package tests.api.java.nio.charset; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestLevel; + /** * Test UTF-16. */ +@TestTargetClass(java.nio.charset.Charset.class) public class UTF16CharsetTest extends AbstractCharsetTestCase { /** @@ -33,6 +39,15 @@ public class UTF16CharsetTest extends AbstractCharsetTestCase { * * @see tests.api.java.nio.charset.ConcreteCharsetTest#testEncode_Normal() */ + @TestInfo( + level = TestLevel.TODO, + purpose = "Empty test.", + targets = { + @TestTarget( + methodName = "", + methodArgs = {} + ) + }) public void testEncode_Normal() { // TODO Auto-generated method stub @@ -43,6 +58,15 @@ public class UTF16CharsetTest extends AbstractCharsetTestCase { * * @see tests.api.java.nio.charset.ConcreteCharsetTest#testDecode_Normal() */ + @TestInfo( + level = TestLevel.TODO, + purpose = "Empty test.", + targets = { + @TestTarget( + methodName = "", + methodArgs = {} + ) + }) public void testDecode_Normal() { // TODO Auto-generated method stub diff --git a/nio_char/src/test/java/tests/api/java/nio/charset/UTF16LECharsetDecoderTest.java b/nio_char/src/test/java/tests/api/java/nio/charset/UTF16LECharsetDecoderTest.java index 183fa47..eed1b12 100644 --- a/nio_char/src/test/java/tests/api/java/nio/charset/UTF16LECharsetDecoderTest.java +++ b/nio_char/src/test/java/tests/api/java/nio/charset/UTF16LECharsetDecoderTest.java @@ -16,6 +16,11 @@ package tests.api.java.nio.charset; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestLevel; + import java.io.UnsupportedEncodingException; import java.nio.ByteBuffer; import java.nio.charset.Charset; @@ -23,6 +28,7 @@ import java.nio.charset.Charset; /** * TODO typedef */ +@TestTargetClass(java.nio.charset.CharsetDecoder.class) public class UTF16LECharsetDecoderTest extends CharsetDecoderTest { protected void setUp() throws Exception { diff --git a/nio_char/src/test/java/tests/api/java/nio/charset/UTF16LECharsetEncoderTest.java b/nio_char/src/test/java/tests/api/java/nio/charset/UTF16LECharsetEncoderTest.java index e669e11..003e1d7 100644 --- a/nio_char/src/test/java/tests/api/java/nio/charset/UTF16LECharsetEncoderTest.java +++ b/nio_char/src/test/java/tests/api/java/nio/charset/UTF16LECharsetEncoderTest.java @@ -16,6 +16,11 @@ package tests.api.java.nio.charset; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestLevel; + import java.nio.CharBuffer; import java.nio.charset.CharacterCodingException; import java.nio.charset.Charset; @@ -23,6 +28,7 @@ import java.nio.charset.Charset; /** * TODO type def */ +@TestTargetClass(java.nio.charset.CharsetEncoder.class) public class UTF16LECharsetEncoderTest extends CharsetEncoderTest { // charset for utf-16le @@ -51,10 +57,28 @@ public class UTF16LECharsetEncoderTest extends CharsetEncoderTest { super.tearDown(); } +@TestInfo( + level = TestLevel.TODO, + purpose = "Empty constructor test.", + targets = { + @TestTarget( + methodName = "CharsetEncoder", + methodArgs = {java.nio.charset.Charset.class, float.class, float.class} + ) + }) public void testCharsetEncoderCharsetfloatfloat() { // this constructor is invalid for UTF16LE CharsetEncoder } +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "IllegalStateException checking missed.", + targets = { + @TestTarget( + methodName = "canEncode", + methodArgs = {char.class} + ) + }) public void testCanEncodechar() throws CharacterCodingException { // normal case for utfCS assertTrue(encoder.canEncode('\u0077')); @@ -64,6 +88,15 @@ public class UTF16LECharsetEncoderTest extends CharsetEncoderTest { assertTrue(encoder.canEncode('\uc2c0')); } +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "IllegalStateException checking missed.", + targets = { + @TestTarget( + methodName = "canEncode", + methodArgs = {java.lang.CharSequence.class} + ) + }) public void testCanEncodeCharSequence() { // normal case for utfCS assertTrue(encoder.canEncode("\u0077")); @@ -82,15 +115,45 @@ public class UTF16LECharsetEncoderTest extends CharsetEncoderTest { assertFalse(encoder.canEncode("\ud800\udb00")); } +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "Regression test. IllegalStateException checking missed.", + targets = { + @TestTarget( + methodName = "canEncode", + methodArgs = {java.lang.CharSequence.class} + ) + }) public void testCanEncodeICUBug() { assertFalse(encoder.canEncode("\ud800")); } +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "averageBytesPerChar", + methodArgs = {} + ), @TestTarget( + methodName = "maxBytesPerChar", + methodArgs = {} + ) + }) public void testSpecificDefaultValue() { assertEquals(2, encoder.averageBytesPerChar(), 0.001); assertEquals(2, encoder.maxBytesPerChar(), 0.001); } +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "isLegalReplacement", + methodArgs = {byte[].class} + ) + }) public void testIsLegalReplacementEmptyArray() { assertTrue(encoder.isLegalReplacement(new byte[0])); } diff --git a/nio_char/src/test/java/tests/api/java/nio/charset/UTF16LECharsetTest.java b/nio_char/src/test/java/tests/api/java/nio/charset/UTF16LECharsetTest.java index b32ab9b..5614eac 100644 --- a/nio_char/src/test/java/tests/api/java/nio/charset/UTF16LECharsetTest.java +++ b/nio_char/src/test/java/tests/api/java/nio/charset/UTF16LECharsetTest.java @@ -16,9 +16,16 @@ package tests.api.java.nio.charset; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestLevel; + /** * Test UTF-16LE. */ + +@TestTargetClass(java.nio.charset.Charset.class) public class UTF16LECharsetTest extends AbstractCharsetTestCase { /** @@ -34,6 +41,15 @@ public class UTF16LECharsetTest extends AbstractCharsetTestCase { * * @see tests.api.java.nio.charset.ConcreteCharsetTest#testEncode_Normal() */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "Functional test, text source: AbstractCharsetTestCase.internalTestEncode. Exceptions checking missed.", + targets = { + @TestTarget( + methodName = "encode", + methodArgs = {java.lang.String.class} + ) + }) public void testEncode_Normal() { String input = "ab\u5D14\u654F"; byte[] output = new byte[] { 97, 0, 98, 0, 20, 93, 79, 101 }; @@ -45,6 +61,15 @@ public class UTF16LECharsetTest extends AbstractCharsetTestCase { * * @see tests.api.java.nio.charset.ConcreteCharsetTest#testDecode_Normal() */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Functional test, text source: AbstractCharsetTestCase.internalTestDecode. Exceptions checking missed.", + targets = { + @TestTarget( + methodName = "decode", + methodArgs = {java.nio.ByteBuffer.class} + ) + }) public void testDecode_Normal() { byte[] input = new byte[] { 97, 0, 98, 0, 20, 93, 79, 101 }; char[] output = "ab\u5D14\u654F".toCharArray(); diff --git a/nio_char/src/test/java/tests/api/java/nio/charset/UTF8CharsetTest.java b/nio_char/src/test/java/tests/api/java/nio/charset/UTF8CharsetTest.java index 8e0f57f..cf22476 100644 --- a/nio_char/src/test/java/tests/api/java/nio/charset/UTF8CharsetTest.java +++ b/nio_char/src/test/java/tests/api/java/nio/charset/UTF8CharsetTest.java @@ -16,9 +16,15 @@ package tests.api.java.nio.charset; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestLevel; + /** * Test UTF-8 charset. */ +@TestTargetClass(java.nio.charset.Charset.class) public class UTF8CharsetTest extends AbstractCharsetTestCase { /** @@ -34,6 +40,15 @@ public class UTF8CharsetTest extends AbstractCharsetTestCase { * * @see tests.api.java.nio.charset.ConcreteCharsetTest#testDecode_Normal() */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "Functional test, text source: AbstractCharsetTestCase.internalTestDecode. Exceptions checking missed.", + targets = { + @TestTarget( + methodName = "decode", + methodArgs = {java.nio.ByteBuffer.class} + ) + }) public void testDecode_Normal() { byte[] input = new byte[] { 97, 98, -27, -76, -108, -26, -107, -113 }; char[] output = "ab\u5D14\u654F".toCharArray(); @@ -45,6 +60,15 @@ public class UTF8CharsetTest extends AbstractCharsetTestCase { * * @see tests.api.java.nio.charset.ConcreteCharsetTest#testEncode_Normal() */ +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "Functional test, text source: AbstractCharsetTestCase.internalTestEncode. Exceptions checking missed.", + targets = { + @TestTarget( + methodName = "encode", + methodArgs = {java.lang.String.class} + ) + }) public void testEncode_Normal() { String input = "ab\u5D14\u654F"; byte[] output = new byte[] { 97, 98, -27, -76, -108, -26, -107, -113 }; diff --git a/nio_char/src/test/java/tests/api/java/nio/charset/UTFCharsetDecoderTest.java b/nio_char/src/test/java/tests/api/java/nio/charset/UTFCharsetDecoderTest.java index 288cd16..16b52eb 100644 --- a/nio_char/src/test/java/tests/api/java/nio/charset/UTFCharsetDecoderTest.java +++ b/nio_char/src/test/java/tests/api/java/nio/charset/UTFCharsetDecoderTest.java @@ -16,6 +16,8 @@ package tests.api.java.nio.charset; +import dalvik.annotation.TestTargetClass; + import java.io.UnsupportedEncodingException; import java.nio.ByteBuffer; import java.nio.charset.Charset; @@ -23,6 +25,7 @@ import java.nio.charset.Charset; /** * test utf-8 decoder */ +@TestTargetClass(java.nio.charset.CharsetDecoder.class) public class UTFCharsetDecoderTest extends CharsetDecoderTest { protected void setUp() throws Exception { diff --git a/nio_char/src/test/java/tests/api/java/nio/charset/UTFCharsetEncoderTest.java b/nio_char/src/test/java/tests/api/java/nio/charset/UTFCharsetEncoderTest.java index b4f1e7d..a7c19d5 100644 --- a/nio_char/src/test/java/tests/api/java/nio/charset/UTFCharsetEncoderTest.java +++ b/nio_char/src/test/java/tests/api/java/nio/charset/UTFCharsetEncoderTest.java @@ -16,6 +16,11 @@ package tests.api.java.nio.charset; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestLevel; + import java.nio.CharBuffer; import java.nio.charset.CharacterCodingException; import java.nio.charset.Charset; @@ -23,6 +28,7 @@ import java.nio.charset.Charset; /** * test case specific activity of utf-8 charset encoder */ +@TestTargetClass(java.nio.charset.CharsetEncoder.class) public class UTFCharsetEncoderTest extends CharsetEncoderTest { // charset for UTF-8 @@ -44,6 +50,15 @@ public class UTFCharsetEncoderTest extends CharsetEncoderTest { super.tearDown(); } +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "IllegalStateException checking missed.", + targets = { + @TestTarget( + methodName = "canEncode", + methodArgs = {char.class} + ) + }) public void testCanEncodechar() throws CharacterCodingException { // normal case for utfCS assertTrue(encoder.canEncode('\u0077')); @@ -53,6 +68,15 @@ public class UTFCharsetEncoderTest extends CharsetEncoderTest { assertTrue(encoder.canEncode('\uc2c0')); } +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "IllegalStateException checking missed.", + targets = { + @TestTarget( + methodName = "canEncode", + methodArgs = {java.lang.CharSequence.class} + ) + }) public void testCanEncodeCharSequence() { // normal case for utfCS assertTrue(encoder.canEncode("\u0077")); @@ -71,10 +95,31 @@ public class UTFCharsetEncoderTest extends CharsetEncoderTest { assertFalse(encoder.canEncode("\ud800\udb00")); } +@TestInfo( + level = TestLevel.PARTIAL, + purpose = "Regression test. IllegalStateException checking missed.", + targets = { + @TestTarget( + methodName = "canEncode", + methodArgs = {java.lang.CharSequence.class} + ) + }) public void testCanEncodeICUBug() { assertFalse(encoder.canEncode("\ud800")); } +@TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "averageBytesPerChar", + methodArgs = {} + ), @TestTarget( + methodName = "maxBytesPerChar", + methodArgs = {} + ) + }) public void testSpecificDefaultValue() { // assertEquals(1.1, encoder.averageBytesPerChar(), 0.0001); assertEquals(2, encoder.averageBytesPerChar(), 0.0001); |