Search in sources :

Example 26 with ByteString

use of com.google.protobuf.ByteString in project j2objc by google.

the class CompatibilityTest method testByteStringSubstring.

public void testByteStringSubstring() throws Exception {
    ByteString bs1 = ByteString.copyFrom("abcdefghijklmnop".getBytes());
    ByteString bs2 = bs1.substring(1, 15);
    assertEquals("bcdefghijklmno", new String(bs2.toByteArray()));
    ByteString bs3 = bs1.substring(12);
    assertEquals("mnop", new String(bs3.toByteArray()));
    ByteString bs4 = bs1.substring(11, 11);
    assertTrue(bs4.isEmpty());
    expectSubstringIndexOutOfBounds(bs1, -1, 1);
    expectSubstringIndexOutOfBounds(bs1, 0, 17);
    expectSubstringIndexOutOfBounds(bs1, 7, 6);
}
Also used : ByteString(com.google.protobuf.ByteString) ByteString(com.google.protobuf.ByteString)

Example 27 with ByteString

use of com.google.protobuf.ByteString in project j2objc by google.

the class ByteStringTest method testToString.

public void testToString() throws Exception {
    ByteString s1 = ByteString.copyFrom("foo".getBytes());
    ByteString s2 = ByteString.copyFrom("你好".getBytes("UTF-8"));
    assertEquals("foo", s1.toString("UTF-8"));
    assertEquals("你好", s2.toString("UTF-8"));
    assertEquals("foo", s1.toStringUtf8());
    assertEquals("你好", s2.toStringUtf8());
}
Also used : ByteString(com.google.protobuf.ByteString)

Example 28 with ByteString

use of com.google.protobuf.ByteString in project j2objc by google.

the class CompatibilityTest method checkGetters.

private void checkGetters(TypicalDataOrBuilder data, FieldDescriptor[] fields) {
    assertEquals(42, data.getMyInt());
    assertEquals("foo", new String(data.getMyBytes().toByteArray()));
    assertEquals(TypicalData.EnumType.VALUE9, data.getMyEnumType());
    assertTrue(data.getMyBool());
    assertEquals(new Float(43.8), data.getMyFloat());
    assertEquals(new Double(44.5), data.getMyDouble());
    assertEquals("bar", data.getMyString());
    assertEquals(24, data.getMyUint());
    assertEquals(4422, data.getMyLong());
    assertEquals(2244, data.getMyUlong());
    assertEquals(1, data.getRepeatedInt32Count());
    assertEquals(72, data.getRepeatedInt32(0));
    assertEquals("aaa", data.getRepeatedString(0));
    assertEquals("ccc", data.getRepeatedString(1));
    assertEquals(1.2, data.getRepeatedDouble(0), 0.0001);
    Object result;
    result = data.getField(fields[1]);
    assertTrue(result instanceof Integer);
    assertEquals(42, result);
    result = data.getField(fields[2]);
    assertTrue(result instanceof ByteString);
    assertEquals("foo", new String(((ByteString) result).toByteArray()));
    result = data.getField(fields[3]);
    assertTrue(result instanceof EnumValueDescriptor);
    assertEquals(9, ((EnumValueDescriptor) result).getNumber());
    result = data.getField(fields[11]);
    assertTrue(result instanceof TypicalDataMessage);
    assertEquals(TypicalDataMessage.newBuilder().build(), result);
    result = data.getField(fields[12]);
    assertTrue(result instanceof Boolean);
    assertEquals(Boolean.TRUE, result);
    result = data.getField(fields[13]);
    assertTrue(result instanceof Float);
    assertEquals(43.8, ((Float) result).floatValue(), 0.0001);
    result = data.getField(fields[14]);
    assertTrue(result instanceof Double);
    assertEquals(44.5, ((Double) result).doubleValue(), 0.0001);
    result = data.getField(fields[15]);
    assertTrue(result instanceof String);
    assertEquals("bar", result);
    result = data.getField(fields[16]);
    assertTrue(result instanceof Integer);
    assertEquals(24, result);
    result = data.getField(fields[17]);
    assertTrue(result instanceof Long);
    assertEquals(4422L, result);
    result = data.getField(fields[18]);
    assertTrue(result instanceof Long);
    assertEquals(2244L, result);
    assertEquals(1, data.getRepeatedFieldCount(fields[4]));
    result = data.getRepeatedField(fields[4], 0);
    assertTrue(result instanceof Integer);
    assertEquals(72, result);
    assertEquals(2, data.getRepeatedFieldCount(fields[8]));
    result = data.getRepeatedField(fields[8], 1);
    assertEquals("ccc", result);
    assertEquals(2, data.getRepeatedFieldCount(fields[7]));
    result = data.getRepeatedField(fields[7], 1);
    assertEquals(3.4, ((Double) result).doubleValue(), 0.0001);
}
Also used : TypicalDataMessage(protos.TypicalDataMessage) ByteString(com.google.protobuf.ByteString) ByteString(com.google.protobuf.ByteString) EnumValueDescriptor(com.google.protobuf.Descriptors.EnumValueDescriptor)

Example 29 with ByteString

use of com.google.protobuf.ByteString in project j2objc by google.

the class CompatibilityTest method testSetAndGetByteString.

public void testSetAndGetByteString() throws Exception {
    ByteString bstr = ByteString.copyFrom("foo".getBytes());
    TypicalData data = TypicalData.newBuilder().setMyBytes(bstr).build();
    assertEquals("foo", new String(data.getMyBytes().toByteArray()));
}
Also used : TypicalData(protos.TypicalData) ByteString(com.google.protobuf.ByteString) ByteString(com.google.protobuf.ByteString)

Example 30 with ByteString

use of com.google.protobuf.ByteString in project j2objc by google.

the class CompatibilityTest method testSetAndGetRepeatedBytes.

public void testSetAndGetRepeatedBytes() throws Exception {
    List<ByteString> list = new ArrayList<ByteString>();
    list.add(ByteString.copyFrom("def".getBytes()));
    list.add(ByteString.copyFrom("ghi".getBytes()));
    TypicalData data = TypicalData.newBuilder().addRepeatedBytes(ByteString.copyFrom("abc".getBytes())).addAllRepeatedBytes(list).setRepeatedBytes(2, ByteString.copyFrom("jkl".getBytes())).build();
    assertEquals(3, data.getRepeatedBytesCount());
    assertEquals("abc", new String(data.getRepeatedBytes(0).toByteArray()));
    byte[] bytes = data.toByteArray();
    TypicalData other = TypicalData.parseFrom(bytes);
    assertEquals("abc", new String(other.getRepeatedBytes(0).toByteArray()));
    assertEquals("def", new String(other.getRepeatedBytesList().get(1).toByteArray()));
    assertEquals("jkl", new String(other.getRepeatedBytes(2).toByteArray()));
}
Also used : TypicalData(protos.TypicalData) ByteString(com.google.protobuf.ByteString) ArrayList(java.util.ArrayList) ByteString(com.google.protobuf.ByteString)

Aggregations

ByteString (com.google.protobuf.ByteString)151 Test (org.junit.Test)35 ArrayList (java.util.ArrayList)30 IOException (java.io.IOException)27 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)18 ServerRequest (com.pokegoapi.main.ServerRequest)13 RequestFailedException (com.pokegoapi.exceptions.request.RequestFailedException)10 Map (java.util.Map)10 HashMap (java.util.HashMap)9 List (java.util.List)9 AggregateResponse (org.apache.hadoop.hbase.protobuf.generated.AggregateProtos.AggregateResponse)9 BeforeTest (org.testng.annotations.BeforeTest)9 Test (org.testng.annotations.Test)9 Connection (org.apache.hadoop.hbase.client.Connection)8 PrivilegedExceptionAction (java.security.PrivilegedExceptionAction)7 Scan (org.apache.hadoop.hbase.client.Scan)7 DeleteRangeResponse (com.coreos.jetcd.api.DeleteRangeResponse)6 RangeResponse (com.coreos.jetcd.api.RangeResponse)6 RpcCallback (com.google.protobuf.RpcCallback)6 RpcController (com.google.protobuf.RpcController)6