1 package com.google.protobuf;
6 import java.nio.ByteBuffer;
7 import java.util.ArrayList;
9 import java.util.logging.Logger;
10 import junit.framework.TestCase;
19 for (
int i = Character.MIN_CODE_POINT;
i < Character.MAX_CODE_POINT;
i++) {
20 if (i < Character.MIN_SURROGATE || i > Character.MAX_SURROGATE) {
21 String
str =
new String(Character.toChars(
i));
31 for (
int i = Byte.MIN_VALUE;
i <= Byte.MAX_VALUE;
i++) {
33 if (!bs.isValidUtf8()) {
39 assertEquals(IsValidUtf8TestUtil.EXPECTED_ONE_BYTE_ROUNDTRIPPABLE_COUNT, valid);
44 for (
int i = Byte.MIN_VALUE;
i <= Byte.MAX_VALUE;
i++) {
45 for (
int j = Byte.MIN_VALUE; j <= Byte.MAX_VALUE; j++) {
47 if (!bs.isValidUtf8()) {
54 assertEquals(IsValidUtf8TestUtil.EXPECTED_TWO_BYTE_ROUNDTRIPPABLE_COUNT, valid);
59 if (System.getenv(
"TRAVIS") ==
null) {
62 for (
int i = Byte.MIN_VALUE;
i <= Byte.MAX_VALUE;
i++) {
63 for (
int j = Byte.MIN_VALUE; j <= Byte.MAX_VALUE; j++) {
64 for (
int k = Byte.MIN_VALUE; k <= Byte.MAX_VALUE; k++) {
67 if (!bs.isValidUtf8()) {
73 if (
count % 1000000L == 0) {
74 logger.info(
"Processed " + (
count / 1000000L) +
" million characters");
79 assertEquals(IsValidUtf8TestUtil.EXPECTED_THREE_BYTE_ROUNDTRIPPABLE_COUNT, valid);
100 assertRoundTrips(
"Quizdeltagerne spiste jordb\u00e6r med fl\u00f8de, mens cirkusklovnen");
103 "\u3044\u308d\u306f\u306b\u307b\u3078\u3068\u3061\u308a\u306c\u308b\u3092");
106 "\u05d3\u05d2 \u05e1\u05e7\u05e8\u05df \u05e9\u05d8 \u05d1\u05d9\u05dd "
107 +
"\u05de\u05d0\u05d5\u05db\u05d6\u05d1 \u05d5\u05dc\u05e4\u05ea\u05e2"
108 +
" \u05de\u05e6\u05d0 \u05dc\u05d5 \u05d7\u05d1\u05e8\u05d4 "
109 +
"\u05d0\u05d9\u05da \u05d4\u05e7\u05dc\u05d9\u05d8\u05d4");
112 " \u0e08\u0e07\u0e1d\u0e48\u0e32\u0e1f\u0e31\u0e19\u0e1e\u0e31\u0e12"
113 +
"\u0e19\u0e32\u0e27\u0e34\u0e0a\u0e32\u0e01\u0e32\u0e23");
116 "\u8fd4\u56de\u94fe\u4e2d\u7684\u4e0b\u4e00\u4e2a\u4ee3\u7406\u9879\u9009\u62e9\u5668");
118 assertRoundTrips(
"\uD841\uDF0E\uD841\uDF31\uD841\uDF79\uD843\uDC53\uD843\uDC78"
119 +
"\uD843\uDC96\uD843\uDCCF\uD843\uDCD5\uD843\uDD15\uD843\uDD7C\uD843\uDD7F"
120 +
"\uD843\uDE0E\uD843\uDE0F\uD843\uDE77\uD843\uDE9D\uD843\uDEA2");
123 "The quick brown \u3044\u308d\u306f\u306b\u307b\u3078\u8fd4\u56de\u94fe"
124 +
"\u4e2d\u7684\u4e0b\u4e00");
165 String
str =
"The quick brown fox jumps over the lazy dog";
171 byte[]
bytes =
"The quick brown fox jumps over the lazy dog".getBytes(
Internal.UTF_8);
179 byte[]
bytes =
new byte[bytesAsInt.length];
180 for (
int i = 0;
i < bytesAsInt.length;
i++) {
200 ByteBuffer direct = ByteBuffer.allocateDirect(
bytes.length);
216 ByteBuffer heap = ByteBuffer.allocate(
bytes.length);
237 }
catch (ArrayIndexOutOfBoundsException e) {
243 }
catch (ArrayIndexOutOfBoundsException e) {
247 ByteBuffer direct = ByteBuffer.allocateDirect(
bytes.length);
253 }
catch (ArrayIndexOutOfBoundsException e) {
259 }
catch (ArrayIndexOutOfBoundsException e) {
263 ByteBuffer heap = ByteBuffer.allocate(
bytes.length);
269 }
catch (ArrayIndexOutOfBoundsException e) {
275 }
catch (ArrayIndexOutOfBoundsException e) {
294 ByteBuffer direct = ByteBuffer.allocateDirect(
bytes.length);
302 ByteBuffer heap = ByteBuffer.allocate(
bytes.length);
312 if (!expected.equals(actual)) {
318 List<String>
codepoints =
new ArrayList<String>();
319 for (
int i = 0;
i <
str.length();
i++) {