private void assertWriteVarint(byte[] data,long value) throws Exception {
  if ((value >>> 32) == 0) {
    ByteArrayOutputStream rawOutput=new ByteArrayOutputStream();
    CodedOutputStream output=CodedOutputStream.newInstance(rawOutput);
    output.writeRawVarint32((int)value);
    output.flush();
    assertEqualBytes(data,rawOutput.toByteArray());
    assertEquals(data.length,CodedOutputStream.computeRawVarint32Size((int)value));
  }
{
    ByteArrayOutputStream rawOutput=new ByteArrayOutputStream();
    CodedOutputStream output=CodedOutputStream.newInstance(rawOutput);
    output.writeRawVarint64(value);
    output.flush();
    assertEqualBytes(data,rawOutput.toByteArray());
    assertEquals(data.length,CodedOutputStream.computeRawVarint64Size(value));
  }
  for (int blockSize=1; blockSize <= 16; blockSize*=2) {
    if ((value >>> 32) == 0) {
      ByteArrayOutputStream rawOutput=new ByteArrayOutputStream();
      CodedOutputStream output=CodedOutputStream.newInstance(rawOutput,blockSize);
      output.writeRawVarint32((int)value);
      output.flush();
      assertEqualBytes(data,rawOutput.toByteArray());
    }
{
      ByteArrayOutputStream rawOutput=new ByteArrayOutputStream();
      CodedOutputStream output=CodedOutputStream.newInstance(rawOutput,blockSize);
      output.writeRawVarint64(value);
      output.flush();
      assertEqualBytes(data,rawOutput.toByteArray());
    }
  }
}

private void assertWriteVarint ( byte [ ] data , long value ) throws Exception { if ( ( value > > > 32 ) == 0 ) { ByteArrayOutputStream rawOutput = new ByteArrayOutputStream ( ) ; CodedOutputStream output = CodedOutputStream . newInstance ( rawOutput ) ; output . writeRawVarint32 ( ( int ) value ) ; output . flush ( ) ; assertEqualBytes ( data , rawOutput . toByteArray ( ) ) ; assertEquals ( data . length , CodedOutputStream . computeRawVarint32Size ( ( int ) value ) ) ; } { ByteArrayOutputStream rawOutput = new ByteArrayOutputStream ( ) ; CodedOutputStream output = CodedOutputStream . newInstance ( rawOutput ) ; output . writeRawVarint64 ( value ) ; output . flush ( ) ; assertEqualBytes ( data , rawOutput . toByteArray ( ) ) ; assertEquals ( data . length , CodedOutputStream . computeRawVarint64Size ( value ) ) ; } for ( int blockSize = 1 ; blockSize <= 16 ; blockSize *= 2 ) { if ( ( value > > > 32 ) == 0 ) { ByteArrayOutputStream rawOutput = new ByteArrayOutputStream ( ) ; CodedOutputStream output = CodedOutputStream . newInstance ( rawOutput , blockSize ) ; output . writeRawVarint32 ( ( int ) value ) ; output . flush ( ) ; assertEqualBytes ( data , rawOutput . toByteArray ( ) ) ; } { ByteArrayOutputStream rawOutput = new ByteArrayOutputStream ( ) ; CodedOutputStream output = CodedOutputStream . newInstance ( rawOutput , blockSize ) ; output . writeRawVarint64 ( value ) ; output . flush ( ) ; assertEqualBytes ( data , rawOutput . toByteArray ( ) ) ; } } }
writes the given value using writerawvarint32 ( ) and writerawvarint64 ( ) and checks that the result matches the given bytes .
