diff options
Diffstat (limited to 'tests/ProtoInputStreamTests')
19 files changed, 385 insertions, 204 deletions
diff --git a/tests/ProtoInputStreamTests/src/com/android/test/protoinputstream/ProtoInputStreamBoolTest.java b/tests/ProtoInputStreamTests/src/com/android/test/protoinputstream/ProtoInputStreamBoolTest.java index c21c4033a0ff..3415d2e13974 100644 --- a/tests/ProtoInputStreamTests/src/com/android/test/protoinputstream/ProtoInputStreamBoolTest.java +++ b/tests/ProtoInputStreamTests/src/com/android/test/protoinputstream/ProtoInputStreamBoolTest.java @@ -384,55 +384,55 @@ public class ProtoInputStreamBoolTest extends TestCase { }; ProtoInputStream pi = new ProtoInputStream(protobuf); - pi.isNextField(fieldId1); + pi.nextField(); try { pi.readFloat(fieldId1); - fail("Should have throw IllegalArgumentException"); + fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); - pi.isNextField(fieldId1); + pi.nextField(); try { pi.readDouble(fieldId1); - fail("Should have throw IllegalArgumentException"); + fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); - pi.isNextField(fieldId1); + pi.nextField(); try { pi.readInt(fieldId1); - fail("Should have throw IllegalArgumentException"); + fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); - pi.isNextField(fieldId1); + pi.nextField(); try { pi.readLong(fieldId1); - fail("Should have throw IllegalArgumentException"); + fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); - pi.isNextField(fieldId1); + pi.nextField(); try { pi.readBytes(fieldId1); - fail("Should have throw IllegalArgumentException"); + fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); - pi.isNextField(fieldId1); + pi.nextField(); try { pi.readString(fieldId1); - fail("Should have throw IllegalArgumentException"); + fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } diff --git a/tests/ProtoInputStreamTests/src/com/android/test/protoinputstream/ProtoInputStreamBytesTest.java b/tests/ProtoInputStreamTests/src/com/android/test/protoinputstream/ProtoInputStreamBytesTest.java index 09fe40edda6c..8796807c0521 100644 --- a/tests/ProtoInputStreamTests/src/com/android/test/protoinputstream/ProtoInputStreamBytesTest.java +++ b/tests/ProtoInputStreamTests/src/com/android/test/protoinputstream/ProtoInputStreamBytesTest.java @@ -306,55 +306,55 @@ public class ProtoInputStreamBytesTest extends TestCase { }; ProtoInputStream pi = new ProtoInputStream(protobuf); - pi.isNextField(fieldId1); + pi.nextField(); try { pi.readFloat(fieldId1); - fail("Should have throw IllegalArgumentException"); + fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); - pi.isNextField(fieldId1); + pi.nextField(); try { pi.readDouble(fieldId1); - fail("Should have throw IllegalArgumentException"); + fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); - pi.isNextField(fieldId1); + pi.nextField(); try { pi.readInt(fieldId1); - fail("Should have throw IllegalArgumentException"); + fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); - pi.isNextField(fieldId1); + pi.nextField(); try { pi.readLong(fieldId1); - fail("Should have throw IllegalArgumentException"); + fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); - pi.isNextField(fieldId1); + pi.nextField(); try { pi.readBoolean(fieldId1); - fail("Should have throw IllegalArgumentException"); + fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); - pi.isNextField(fieldId1); + pi.nextField(); try { pi.readString(fieldId1); - fail("Should have throw IllegalArgumentException"); + fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } diff --git a/tests/ProtoInputStreamTests/src/com/android/test/protoinputstream/ProtoInputStreamDoubleTest.java b/tests/ProtoInputStreamTests/src/com/android/test/protoinputstream/ProtoInputStreamDoubleTest.java index 118fe3431e01..2b54e960eabb 100644 --- a/tests/ProtoInputStreamTests/src/com/android/test/protoinputstream/ProtoInputStreamDoubleTest.java +++ b/tests/ProtoInputStreamTests/src/com/android/test/protoinputstream/ProtoInputStreamDoubleTest.java @@ -611,55 +611,55 @@ public class ProtoInputStreamDoubleTest extends TestCase { }; ProtoInputStream pi = new ProtoInputStream(protobuf); - pi.isNextField(fieldId1); + pi.nextField(); try { pi.readFloat(fieldId1); - fail("Should have throw IllegalArgumentException"); + fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); - pi.isNextField(fieldId1); + pi.nextField(); try { pi.readBoolean(fieldId1); - fail("Should have throw IllegalArgumentException"); + fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); - pi.isNextField(fieldId1); + pi.nextField(); try { pi.readInt(fieldId1); - fail("Should have throw IllegalArgumentException"); + fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); - pi.isNextField(fieldId1); + pi.nextField(); try { pi.readLong(fieldId1); - fail("Should have throw IllegalArgumentException"); + fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); - pi.isNextField(fieldId1); + pi.nextField(); try { pi.readBytes(fieldId1); - fail("Should have throw IllegalArgumentException"); + fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); - pi.isNextField(fieldId1); + pi.nextField(); try { pi.readString(fieldId1); - fail("Should have throw IllegalArgumentException"); + fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } diff --git a/tests/ProtoInputStreamTests/src/com/android/test/protoinputstream/ProtoInputStreamEnumTest.java b/tests/ProtoInputStreamTests/src/com/android/test/protoinputstream/ProtoInputStreamEnumTest.java index f55d95129588..19bad7099622 100644 --- a/tests/ProtoInputStreamTests/src/com/android/test/protoinputstream/ProtoInputStreamEnumTest.java +++ b/tests/ProtoInputStreamTests/src/com/android/test/protoinputstream/ProtoInputStreamEnumTest.java @@ -454,55 +454,55 @@ public class ProtoInputStreamEnumTest extends TestCase { }; ProtoInputStream pi = new ProtoInputStream(protobuf); - pi.isNextField(fieldId1); + pi.nextField(); try { pi.readFloat(fieldId1); - fail("Should have throw IllegalArgumentException"); + fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); - pi.isNextField(fieldId1); + pi.nextField(); try { pi.readDouble(fieldId1); - fail("Should have throw IllegalArgumentException"); + fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); - pi.isNextField(fieldId1); + pi.nextField(); try { pi.readBoolean(fieldId1); - fail("Should have throw IllegalArgumentException"); + fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); - pi.isNextField(fieldId1); + pi.nextField(); try { pi.readLong(fieldId1); - fail("Should have throw IllegalArgumentException"); + fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); - pi.isNextField(fieldId1); + pi.nextField(); try { pi.readBytes(fieldId1); - fail("Should have throw IllegalArgumentException"); + fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); - pi.isNextField(fieldId1); + pi.nextField(); try { pi.readString(fieldId1); - fail("Should have throw IllegalArgumentException"); + fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } diff --git a/tests/ProtoInputStreamTests/src/com/android/test/protoinputstream/ProtoInputStreamFixed32Test.java b/tests/ProtoInputStreamTests/src/com/android/test/protoinputstream/ProtoInputStreamFixed32Test.java index df68476f0c36..2bc61a0c7e8a 100644 --- a/tests/ProtoInputStreamTests/src/com/android/test/protoinputstream/ProtoInputStreamFixed32Test.java +++ b/tests/ProtoInputStreamTests/src/com/android/test/protoinputstream/ProtoInputStreamFixed32Test.java @@ -431,55 +431,55 @@ public class ProtoInputStreamFixed32Test extends TestCase { }; ProtoInputStream pi = new ProtoInputStream(protobuf); - pi.isNextField(fieldId1); + pi.nextField(); try { pi.readFloat(fieldId1); - fail("Should have throw IllegalArgumentException"); + fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); - pi.isNextField(fieldId1); + pi.nextField(); try { pi.readDouble(fieldId1); - fail("Should have throw IllegalArgumentException"); + fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); - pi.isNextField(fieldId1); + pi.nextField(); try { pi.readBoolean(fieldId1); - fail("Should have throw IllegalArgumentException"); + fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); - pi.isNextField(fieldId1); + pi.nextField(); try { pi.readLong(fieldId1); - fail("Should have throw IllegalArgumentException"); + fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); - pi.isNextField(fieldId1); + pi.nextField(); try { pi.readBytes(fieldId1); - fail("Should have throw IllegalArgumentException"); + fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); - pi.isNextField(fieldId1); + pi.nextField(); try { pi.readString(fieldId1); - fail("Should have throw IllegalArgumentException"); + fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } diff --git a/tests/ProtoInputStreamTests/src/com/android/test/protoinputstream/ProtoInputStreamFixed64Test.java b/tests/ProtoInputStreamTests/src/com/android/test/protoinputstream/ProtoInputStreamFixed64Test.java index af4130b28cd8..a54ecf99d62c 100644 --- a/tests/ProtoInputStreamTests/src/com/android/test/protoinputstream/ProtoInputStreamFixed64Test.java +++ b/tests/ProtoInputStreamTests/src/com/android/test/protoinputstream/ProtoInputStreamFixed64Test.java @@ -532,55 +532,55 @@ public class ProtoInputStreamFixed64Test extends TestCase { }; ProtoInputStream pi = new ProtoInputStream(protobuf); - pi.isNextField(fieldId1); + pi.nextField(); try { pi.readFloat(fieldId1); - fail("Should have throw IllegalArgumentException"); + fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); - pi.isNextField(fieldId1); + pi.nextField(); try { pi.readDouble(fieldId1); - fail("Should have throw IllegalArgumentException"); + fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); - pi.isNextField(fieldId1); + pi.nextField(); try { pi.readInt(fieldId1); - fail("Should have throw IllegalArgumentException"); + fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); - pi.isNextField(fieldId1); + pi.nextField(); try { pi.readBoolean(fieldId1); - fail("Should have throw IllegalArgumentException"); + fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); - pi.isNextField(fieldId1); + pi.nextField(); try { pi.readBytes(fieldId1); - fail("Should have throw IllegalArgumentException"); + fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); - pi.isNextField(fieldId1); + pi.nextField(); try { pi.readString(fieldId1); - fail("Should have throw IllegalArgumentException"); + fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } diff --git a/tests/ProtoInputStreamTests/src/com/android/test/protoinputstream/ProtoInputStreamFloatTest.java b/tests/ProtoInputStreamTests/src/com/android/test/protoinputstream/ProtoInputStreamFloatTest.java index 9bc07dc513e1..0477e9ea74e0 100644 --- a/tests/ProtoInputStreamTests/src/com/android/test/protoinputstream/ProtoInputStreamFloatTest.java +++ b/tests/ProtoInputStreamTests/src/com/android/test/protoinputstream/ProtoInputStreamFloatTest.java @@ -563,55 +563,55 @@ public class ProtoInputStreamFloatTest extends TestCase { }; ProtoInputStream pi = new ProtoInputStream(protobuf); - pi.isNextField(fieldId1); + pi.nextField(); try { pi.readBoolean(fieldId1); - fail("Should have throw IllegalArgumentException"); + fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); - pi.isNextField(fieldId1); + pi.nextField(); try { pi.readDouble(fieldId1); - fail("Should have throw IllegalArgumentException"); + fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); - pi.isNextField(fieldId1); + pi.nextField(); try { pi.readInt(fieldId1); - fail("Should have throw IllegalArgumentException"); + fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); - pi.isNextField(fieldId1); + pi.nextField(); try { pi.readLong(fieldId1); - fail("Should have throw IllegalArgumentException"); + fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); - pi.isNextField(fieldId1); + pi.nextField(); try { pi.readBytes(fieldId1); - fail("Should have throw IllegalArgumentException"); + fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); - pi.isNextField(fieldId1); + pi.nextField(); try { pi.readString(fieldId1); - fail("Should have throw IllegalArgumentException"); + fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } diff --git a/tests/ProtoInputStreamTests/src/com/android/test/protoinputstream/ProtoInputStreamIncompleteValueTest.java b/tests/ProtoInputStreamTests/src/com/android/test/protoinputstream/ProtoInputStreamIncompleteValueTest.java new file mode 100644 index 000000000000..167d5a438302 --- /dev/null +++ b/tests/ProtoInputStreamTests/src/com/android/test/protoinputstream/ProtoInputStreamIncompleteValueTest.java @@ -0,0 +1,180 @@ +/* + * Copyright (C) 2020 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.test.protoinputstream; + +import android.util.proto.ProtoInputStream; +import android.util.proto.ProtoParseException; +import android.util.proto.ProtoStream; + +import junit.framework.TestCase; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; + +public class ProtoInputStreamIncompleteValueTest extends TestCase { + + /** + * Test that an incomplete varint at the end of a stream throws an exception + */ + public void testIncompleteVarint() throws IOException { + final long fieldFlags = ProtoStream.FIELD_COUNT_SINGLE | ProtoStream.FIELD_TYPE_INT32; + + final long fieldId1 = fieldFlags | ((long) 1 & 0x0ffffffffL); + + final byte[] protobuf = new byte[]{ + // 1 : varint -> invalid varint value + (byte) 0x08, + (byte) 0xff, + }; + + InputStream stream = new ByteArrayInputStream(protobuf); + final ProtoInputStream pi = new ProtoInputStream(stream); + + while (pi.nextField() != ProtoInputStream.NO_MORE_FIELDS) { + try { + switch (pi.getFieldNumber()) { + case (int) fieldId1: + pi.readInt(fieldId1); + fail("Should have thrown a ProtoParseException"); + break; + default: + fail("Unexpected field id " + pi.getFieldNumber()); + } + } catch (ProtoParseException ppe) { + // good + stream.close(); + return; + } + } + stream.close(); + fail("Test should not have reached this point..."); + } + + /** + * Test that an incomplete fixed64 at the end of a stream throws an exception + */ + public void testIncompleteFixed64() throws IOException { + final long fieldFlags = ProtoStream.FIELD_COUNT_SINGLE | ProtoStream.FIELD_TYPE_FIXED64; + + final long fieldId2 = fieldFlags | ((long) 2 & 0x0ffffffffL); + + final byte[] protobuf = new byte[]{ + // 2 -> invalid fixed64 + (byte) 0x11, + (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x00, + (byte) 0x00, (byte) 0x00, (byte) 0x00, + }; + + InputStream stream = new ByteArrayInputStream(protobuf); + final ProtoInputStream pi = new ProtoInputStream(stream); + + while (pi.nextField() != ProtoInputStream.NO_MORE_FIELDS) { + try { + switch (pi.getFieldNumber()) { + case (int) fieldId2: + pi.readLong(fieldId2); + fail("Should have thrown a ProtoParseException"); + break; + default: + fail("Unexpected field id " + pi.getFieldNumber()); + } + } catch (ProtoParseException ppe) { + // good + stream.close(); + return; + } + } + stream.close(); + fail("Test should not have reached this point..."); + } + + /** + * Test that an incomplete length delimited value at the end of a stream throws an exception + */ + public void testIncompleteLengthDelimited() throws IOException { + final long fieldFlags = ProtoStream.FIELD_COUNT_SINGLE | ProtoStream.FIELD_TYPE_BYTES; + + final long fieldId5 = fieldFlags | ((long) 5 & 0x0ffffffffL); + + final byte[] protobuf = new byte[]{ + // 5 -> invalid byte array (has size 5 but only 4 values) + (byte) 0x2a, + (byte) 0x05, + (byte) 0x00, (byte) 0x01, (byte) 0x02, (byte) 0x03, + }; + + InputStream stream = new ByteArrayInputStream(protobuf); + final ProtoInputStream pi = new ProtoInputStream(stream); + + while (pi.nextField() != ProtoInputStream.NO_MORE_FIELDS) { + try { + switch (pi.getFieldNumber()) { + case (int) fieldId5: + pi.readBytes(fieldId5); + fail("Should have thrown a ProtoParseException"); + break; + default: + fail("Unexpected field id " + pi.getFieldNumber()); + } + } catch (ProtoParseException ppe) { + // good + stream.close(); + return; + } + } + stream.close(); + fail("Test should not have reached this point..."); + } + + /** + * Test that an incomplete fixed32 at the end of a stream throws an exception + */ + public void testIncompleteFixed32() throws IOException { + final long fieldFlags = ProtoStream.FIELD_COUNT_SINGLE | ProtoStream.FIELD_TYPE_FIXED32; + + final long fieldId2 = fieldFlags | ((long) 2 & 0x0ffffffffL); + + final byte[] protobuf = new byte[]{ + // 2 -> invalid fixed32 + (byte) 0x15, + (byte) 0x01, (byte) 0x00, (byte) 0x00, + }; + + InputStream stream = new ByteArrayInputStream(protobuf); + final ProtoInputStream pi = new ProtoInputStream(stream); + + while (pi.nextField() != ProtoInputStream.NO_MORE_FIELDS) { + try { + switch (pi.getFieldNumber()) { + case (int) fieldId2: + pi.readInt(fieldId2); + fail("Should have thrown a ProtoParseException"); + break; + default: + fail("Unexpected field id " + pi.getFieldNumber()); + } + } catch (ProtoParseException ppe) { + // good + stream.close(); + return; + } + } + stream.close(); + fail("Test should not have reached this point..."); + } +} diff --git a/tests/ProtoInputStreamTests/src/com/android/test/protoinputstream/ProtoInputStreamInt32Test.java b/tests/ProtoInputStreamTests/src/com/android/test/protoinputstream/ProtoInputStreamInt32Test.java index 0065870486f2..a7f3f65e504d 100644 --- a/tests/ProtoInputStreamTests/src/com/android/test/protoinputstream/ProtoInputStreamInt32Test.java +++ b/tests/ProtoInputStreamTests/src/com/android/test/protoinputstream/ProtoInputStreamInt32Test.java @@ -449,55 +449,55 @@ public class ProtoInputStreamInt32Test extends TestCase { }; ProtoInputStream pi = new ProtoInputStream(protobuf); - pi.isNextField(fieldId1); + pi.nextField(); try { pi.readFloat(fieldId1); - fail("Should have throw IllegalArgumentException"); + fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); - pi.isNextField(fieldId1); + pi.nextField(); try { pi.readDouble(fieldId1); - fail("Should have throw IllegalArgumentException"); + fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); - pi.isNextField(fieldId1); + pi.nextField(); try { pi.readBoolean(fieldId1); - fail("Should have throw IllegalArgumentException"); + fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); - pi.isNextField(fieldId1); + pi.nextField(); try { pi.readLong(fieldId1); - fail("Should have throw IllegalArgumentException"); + fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); - pi.isNextField(fieldId1); + pi.nextField(); try { pi.readBytes(fieldId1); - fail("Should have throw IllegalArgumentException"); + fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); - pi.isNextField(fieldId1); + pi.nextField(); try { pi.readString(fieldId1); - fail("Should have throw IllegalArgumentException"); + fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } diff --git a/tests/ProtoInputStreamTests/src/com/android/test/protoinputstream/ProtoInputStreamInt64Test.java b/tests/ProtoInputStreamTests/src/com/android/test/protoinputstream/ProtoInputStreamInt64Test.java index 4d6d105e60b0..dc42468e0605 100644 --- a/tests/ProtoInputStreamTests/src/com/android/test/protoinputstream/ProtoInputStreamInt64Test.java +++ b/tests/ProtoInputStreamTests/src/com/android/test/protoinputstream/ProtoInputStreamInt64Test.java @@ -529,55 +529,55 @@ public class ProtoInputStreamInt64Test extends TestCase { }; ProtoInputStream pi = new ProtoInputStream(protobuf); - pi.isNextField(fieldId1); + pi.nextField(); try { pi.readFloat(fieldId1); - fail("Should have throw IllegalArgumentException"); + fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); - pi.isNextField(fieldId1); + pi.nextField(); try { pi.readDouble(fieldId1); - fail("Should have throw IllegalArgumentException"); + fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); - pi.isNextField(fieldId1); + pi.nextField(); try { pi.readInt(fieldId1); - fail("Should have throw IllegalArgumentException"); + fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); - pi.isNextField(fieldId1); + pi.nextField(); try { pi.readBoolean(fieldId1); - fail("Should have throw IllegalArgumentException"); + fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); - pi.isNextField(fieldId1); + pi.nextField(); try { pi.readBytes(fieldId1); - fail("Should have throw IllegalArgumentException"); + fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); - pi.isNextField(fieldId1); + pi.nextField(); try { pi.readString(fieldId1); - fail("Should have throw IllegalArgumentException"); + fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } diff --git a/tests/ProtoInputStreamTests/src/com/android/test/protoinputstream/ProtoInputStreamObjectTest.java b/tests/ProtoInputStreamTests/src/com/android/test/protoinputstream/ProtoInputStreamObjectTest.java index 5e49eeafb8af..1c0832e3e676 100644 --- a/tests/ProtoInputStreamTests/src/com/android/test/protoinputstream/ProtoInputStreamObjectTest.java +++ b/tests/ProtoInputStreamTests/src/com/android/test/protoinputstream/ProtoInputStreamObjectTest.java @@ -391,55 +391,55 @@ public class ProtoInputStreamObjectTest extends TestCase { }; ProtoInputStream pi = new ProtoInputStream(protobuf); - pi.isNextField(fieldId1); + pi.nextField(); try { pi.readFloat(fieldId1); - fail("Should have throw IllegalArgumentException"); + fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); - pi.isNextField(fieldId1); + pi.nextField(); try { pi.readDouble(fieldId1); - fail("Should have throw IllegalArgumentException"); + fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); - pi.isNextField(fieldId1); + pi.nextField(); try { pi.readInt(fieldId1); - fail("Should have throw IllegalArgumentException"); + fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); - pi.isNextField(fieldId1); + pi.nextField(); try { pi.readLong(fieldId1); - fail("Should have throw IllegalArgumentException"); + fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); - pi.isNextField(fieldId1); + pi.nextField(); try { pi.readBoolean(fieldId1); - fail("Should have throw IllegalArgumentException"); + fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); - pi.isNextField(fieldId1); + pi.nextField(); try { pi.readString(fieldId1); - fail("Should have throw IllegalArgumentException"); + fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } diff --git a/tests/ProtoInputStreamTests/src/com/android/test/protoinputstream/ProtoInputStreamSFixed32Test.java b/tests/ProtoInputStreamTests/src/com/android/test/protoinputstream/ProtoInputStreamSFixed32Test.java index 75c88a44614b..d349ea2baa67 100644 --- a/tests/ProtoInputStreamTests/src/com/android/test/protoinputstream/ProtoInputStreamSFixed32Test.java +++ b/tests/ProtoInputStreamTests/src/com/android/test/protoinputstream/ProtoInputStreamSFixed32Test.java @@ -431,55 +431,55 @@ public class ProtoInputStreamSFixed32Test extends TestCase { }; ProtoInputStream pi = new ProtoInputStream(protobuf); - pi.isNextField(fieldId1); + pi.nextField(); try { pi.readFloat(fieldId1); - fail("Should have throw IllegalArgumentException"); + fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); - pi.isNextField(fieldId1); + pi.nextField(); try { pi.readDouble(fieldId1); - fail("Should have throw IllegalArgumentException"); + fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); - pi.isNextField(fieldId1); + pi.nextField(); try { pi.readBoolean(fieldId1); - fail("Should have throw IllegalArgumentException"); + fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); - pi.isNextField(fieldId1); + pi.nextField(); try { pi.readLong(fieldId1); - fail("Should have throw IllegalArgumentException"); + fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); - pi.isNextField(fieldId1); + pi.nextField(); try { pi.readBytes(fieldId1); - fail("Should have throw IllegalArgumentException"); + fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); - pi.isNextField(fieldId1); + pi.nextField(); try { pi.readString(fieldId1); - fail("Should have throw IllegalArgumentException"); + fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } diff --git a/tests/ProtoInputStreamTests/src/com/android/test/protoinputstream/ProtoInputStreamSFixed64Test.java b/tests/ProtoInputStreamTests/src/com/android/test/protoinputstream/ProtoInputStreamSFixed64Test.java index 4c65cf49318d..81a9c591b32e 100644 --- a/tests/ProtoInputStreamTests/src/com/android/test/protoinputstream/ProtoInputStreamSFixed64Test.java +++ b/tests/ProtoInputStreamTests/src/com/android/test/protoinputstream/ProtoInputStreamSFixed64Test.java @@ -531,55 +531,55 @@ public class ProtoInputStreamSFixed64Test extends TestCase { }; ProtoInputStream pi = new ProtoInputStream(protobuf); - pi.isNextField(fieldId1); + pi.nextField(); try { pi.readFloat(fieldId1); - fail("Should have throw IllegalArgumentException"); + fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); - pi.isNextField(fieldId1); + pi.nextField(); try { pi.readDouble(fieldId1); - fail("Should have throw IllegalArgumentException"); + fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); - pi.isNextField(fieldId1); + pi.nextField(); try { pi.readInt(fieldId1); - fail("Should have throw IllegalArgumentException"); + fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); - pi.isNextField(fieldId1); + pi.nextField(); try { pi.readBoolean(fieldId1); - fail("Should have throw IllegalArgumentException"); + fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); - pi.isNextField(fieldId1); + pi.nextField(); try { pi.readBytes(fieldId1); - fail("Should have throw IllegalArgumentException"); + fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); - pi.isNextField(fieldId1); + pi.nextField(); try { pi.readString(fieldId1); - fail("Should have throw IllegalArgumentException"); + fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } diff --git a/tests/ProtoInputStreamTests/src/com/android/test/protoinputstream/ProtoInputStreamSInt32Test.java b/tests/ProtoInputStreamTests/src/com/android/test/protoinputstream/ProtoInputStreamSInt32Test.java index 6854cd8aad28..97194444deb2 100644 --- a/tests/ProtoInputStreamTests/src/com/android/test/protoinputstream/ProtoInputStreamSInt32Test.java +++ b/tests/ProtoInputStreamTests/src/com/android/test/protoinputstream/ProtoInputStreamSInt32Test.java @@ -431,55 +431,55 @@ public class ProtoInputStreamSInt32Test extends TestCase { }; ProtoInputStream pi = new ProtoInputStream(protobuf); - pi.isNextField(fieldId1); + pi.nextField(); try { pi.readFloat(fieldId1); - fail("Should have throw IllegalArgumentException"); + fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); - pi.isNextField(fieldId1); + pi.nextField(); try { pi.readDouble(fieldId1); - fail("Should have throw IllegalArgumentException"); + fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); - pi.isNextField(fieldId1); + pi.nextField(); try { pi.readBoolean(fieldId1); - fail("Should have throw IllegalArgumentException"); + fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); - pi.isNextField(fieldId1); + pi.nextField(); try { pi.readLong(fieldId1); - fail("Should have throw IllegalArgumentException"); + fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); - pi.isNextField(fieldId1); + pi.nextField(); try { pi.readBytes(fieldId1); - fail("Should have throw IllegalArgumentException"); + fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); - pi.isNextField(fieldId1); + pi.nextField(); try { pi.readString(fieldId1); - fail("Should have throw IllegalArgumentException"); + fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } diff --git a/tests/ProtoInputStreamTests/src/com/android/test/protoinputstream/ProtoInputStreamSInt64Test.java b/tests/ProtoInputStreamTests/src/com/android/test/protoinputstream/ProtoInputStreamSInt64Test.java index c53e9d72562a..118476cdf235 100644 --- a/tests/ProtoInputStreamTests/src/com/android/test/protoinputstream/ProtoInputStreamSInt64Test.java +++ b/tests/ProtoInputStreamTests/src/com/android/test/protoinputstream/ProtoInputStreamSInt64Test.java @@ -506,55 +506,55 @@ public class ProtoInputStreamSInt64Test extends TestCase { }; ProtoInputStream pi = new ProtoInputStream(protobuf); - pi.isNextField(fieldId1); + pi.nextField(); try { pi.readFloat(fieldId1); - fail("Should have throw IllegalArgumentException"); + fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); - pi.isNextField(fieldId1); + pi.nextField(); try { pi.readDouble(fieldId1); - fail("Should have throw IllegalArgumentException"); + fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); - pi.isNextField(fieldId1); + pi.nextField(); try { pi.readInt(fieldId1); - fail("Should have throw IllegalArgumentException"); + fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); - pi.isNextField(fieldId1); + pi.nextField(); try { pi.readBoolean(fieldId1); - fail("Should have throw IllegalArgumentException"); + fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); - pi.isNextField(fieldId1); + pi.nextField(); try { pi.readBytes(fieldId1); - fail("Should have throw IllegalArgumentException"); + fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); - pi.isNextField(fieldId1); + pi.nextField(); try { pi.readString(fieldId1); - fail("Should have throw IllegalArgumentException"); + fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } diff --git a/tests/ProtoInputStreamTests/src/com/android/test/protoinputstream/ProtoInputStreamStringTest.java b/tests/ProtoInputStreamTests/src/com/android/test/protoinputstream/ProtoInputStreamStringTest.java index 816d5f900a3d..51ee78f32767 100644 --- a/tests/ProtoInputStreamTests/src/com/android/test/protoinputstream/ProtoInputStreamStringTest.java +++ b/tests/ProtoInputStreamTests/src/com/android/test/protoinputstream/ProtoInputStreamStringTest.java @@ -287,55 +287,55 @@ public class ProtoInputStreamStringTest extends TestCase { }; ProtoInputStream pi = new ProtoInputStream(protobuf); - pi.isNextField(fieldId1); + pi.nextField(); try { pi.readFloat(fieldId1); - fail("Should have throw IllegalArgumentException"); + fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); - pi.isNextField(fieldId1); + pi.nextField(); try { pi.readDouble(fieldId1); - fail("Should have throw IllegalArgumentException"); + fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); - pi.isNextField(fieldId1); + pi.nextField(); try { pi.readInt(fieldId1); - fail("Should have throw IllegalArgumentException"); + fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); - pi.isNextField(fieldId1); + pi.nextField(); try { pi.readLong(fieldId1); - fail("Should have throw IllegalArgumentException"); + fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); - pi.isNextField(fieldId1); + pi.nextField(); try { pi.readBytes(fieldId1); - fail("Should have throw IllegalArgumentException"); + fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); - pi.isNextField(fieldId1); + pi.nextField(); try { pi.readBoolean(fieldId1); - fail("Should have throw IllegalArgumentException"); + fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } diff --git a/tests/ProtoInputStreamTests/src/com/android/test/protoinputstream/ProtoInputStreamUInt32Test.java b/tests/ProtoInputStreamTests/src/com/android/test/protoinputstream/ProtoInputStreamUInt32Test.java index 50fc537767a4..42f3e991f6e8 100644 --- a/tests/ProtoInputStreamTests/src/com/android/test/protoinputstream/ProtoInputStreamUInt32Test.java +++ b/tests/ProtoInputStreamTests/src/com/android/test/protoinputstream/ProtoInputStreamUInt32Test.java @@ -448,55 +448,55 @@ public class ProtoInputStreamUInt32Test extends TestCase { }; ProtoInputStream pi = new ProtoInputStream(protobuf); - pi.isNextField(fieldId1); + pi.nextField(); try { pi.readFloat(fieldId1); - fail("Should have throw IllegalArgumentException"); + fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); - pi.isNextField(fieldId1); + pi.nextField(); try { pi.readDouble(fieldId1); - fail("Should have throw IllegalArgumentException"); + fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); - pi.isNextField(fieldId1); + pi.nextField(); try { pi.readBoolean(fieldId1); - fail("Should have throw IllegalArgumentException"); + fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); - pi.isNextField(fieldId1); + pi.nextField(); try { pi.readLong(fieldId1); - fail("Should have throw IllegalArgumentException"); + fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); - pi.isNextField(fieldId1); + pi.nextField(); try { pi.readBytes(fieldId1); - fail("Should have throw IllegalArgumentException"); + fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); - pi.isNextField(fieldId1); + pi.nextField(); try { pi.readString(fieldId1); - fail("Should have throw IllegalArgumentException"); + fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } diff --git a/tests/ProtoInputStreamTests/src/com/android/test/protoinputstream/ProtoInputStreamUInt64Test.java b/tests/ProtoInputStreamTests/src/com/android/test/protoinputstream/ProtoInputStreamUInt64Test.java index 20969e9056a9..8ba2c0ccaca9 100644 --- a/tests/ProtoInputStreamTests/src/com/android/test/protoinputstream/ProtoInputStreamUInt64Test.java +++ b/tests/ProtoInputStreamTests/src/com/android/test/protoinputstream/ProtoInputStreamUInt64Test.java @@ -525,55 +525,55 @@ public class ProtoInputStreamUInt64Test extends TestCase { }; ProtoInputStream pi = new ProtoInputStream(protobuf); - pi.isNextField(fieldId1); + pi.nextField(); try { pi.readFloat(fieldId1); - fail("Should have throw IllegalArgumentException"); + fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); - pi.isNextField(fieldId1); + pi.nextField(); try { pi.readDouble(fieldId1); - fail("Should have throw IllegalArgumentException"); + fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); - pi.isNextField(fieldId1); + pi.nextField(); try { pi.readInt(fieldId1); - fail("Should have throw IllegalArgumentException"); + fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); - pi.isNextField(fieldId1); + pi.nextField(); try { pi.readBoolean(fieldId1); - fail("Should have throw IllegalArgumentException"); + fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); - pi.isNextField(fieldId1); + pi.nextField(); try { pi.readBytes(fieldId1); - fail("Should have throw IllegalArgumentException"); + fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } pi = new ProtoInputStream(protobuf); - pi.isNextField(fieldId1); + pi.nextField(); try { pi.readString(fieldId1); - fail("Should have throw IllegalArgumentException"); + fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException iae) { // good } diff --git a/tests/ProtoInputStreamTests/src/com/android/test/protoinputstream/ProtoTests.java b/tests/ProtoInputStreamTests/src/com/android/test/protoinputstream/ProtoTests.java index cdf6ae20f370..685110c08147 100644 --- a/tests/ProtoInputStreamTests/src/com/android/test/protoinputstream/ProtoTests.java +++ b/tests/ProtoInputStreamTests/src/com/android/test/protoinputstream/ProtoTests.java @@ -39,6 +39,7 @@ public class ProtoTests { suite.addTestSuite(ProtoInputStreamBytesTest.class); suite.addTestSuite(ProtoInputStreamEnumTest.class); suite.addTestSuite(ProtoInputStreamObjectTest.class); + suite.addTestSuite(ProtoInputStreamIncompleteValueTest.class); return suite; } |