31 package com.google.protobuf;
42 import junit.framework.TestCase;
59 testBytes(LITERAL_FACTORY, 1, EXPECTED_ONE_BYTE_ROUNDTRIPPABLE_COUNT);
60 testBytes(HEAP_NIO_FACTORY, 1, EXPECTED_ONE_BYTE_ROUNDTRIPPABLE_COUNT);
61 testBytes(DIRECT_NIO_FACTORY, 1, EXPECTED_ONE_BYTE_ROUNDTRIPPABLE_COUNT);
66 testBytes(LITERAL_FACTORY, 2, IsValidUtf8TestUtil.EXPECTED_TWO_BYTE_ROUNDTRIPPABLE_COUNT);
67 testBytes(HEAP_NIO_FACTORY, 2, IsValidUtf8TestUtil.EXPECTED_TWO_BYTE_ROUNDTRIPPABLE_COUNT);
68 testBytes(DIRECT_NIO_FACTORY, 2, IsValidUtf8TestUtil.EXPECTED_TWO_BYTE_ROUNDTRIPPABLE_COUNT);
74 if (System.getenv(
"TRAVIS") ==
null) {
75 testBytes(LITERAL_FACTORY, 3, EXPECTED_THREE_BYTE_ROUNDTRIPPABLE_COUNT);
76 testBytes(HEAP_NIO_FACTORY, 3, EXPECTED_THREE_BYTE_ROUNDTRIPPABLE_COUNT);
77 testBytes(DIRECT_NIO_FACTORY, 3, EXPECTED_THREE_BYTE_ROUNDTRIPPABLE_COUNT);
102 assertTrue(
asBytes(
"").isValidUtf8());
105 assertTrue(
asBytes(
"\u0000abc\u007f").isValidUtf8());
108 assertTrue(
asBytes(
"\u00a2\u00a2").isValidUtf8());
111 assertTrue(
asBytes(
"\u020ac\u020ac").isValidUtf8());
114 assertTrue(
asBytes(
"\u024B62\u024B62").isValidUtf8());
117 assertTrue(
asBytes(
"a\u020ac\u00a2b\\u024B62u020acc\u00a2de\u024B62").isValidUtf8());
124 byte[] realBytes =
new byte[
bytes.length];
125 for (
int i = 0;
i <
bytes.length;
i++) {
133 assertTrue(not ^ Utf8.isValidUtf8(realBytes));
134 assertTrue(not ^ Utf8.isValidUtf8(realBytes, 0,
bytes.length));
135 ByteString leaf = factory.newByteString(realBytes);
137 assertTrue(not ^ leaf.isValidUtf8());
138 assertTrue(not ^ sub.isValidUtf8());
144 RopeByteString.newInstanceForTest(sub, leaf)
147 assertTrue(not ^ rope.isValidUtf8());
170 for (Shard shard : IsValidUtf8TestUtil.FOUR_BYTE_SHARDS) {
171 actual = (int) (actual + shard.expected);
173 assertEquals(IsValidUtf8TestUtil.EXPECTED_FOUR_BYTE_ROUNDTRIPPABLE_COUNT, actual);