diff options
author | Viktor Szathmáry <phraktle@gmail.com> | 2014-09-09 16:31:51 +0200 |
---|---|---|
committer | Tamir Duberstein <tamird@gmail.com> | 2015-04-02 14:48:43 -0700 |
commit | e84893f6768f136cc86e2db69fc1d40ff2be7e3b (patch) | |
tree | c36057efe7fc3c3bf50381c96bae16cf73234fa5 /java/src/test/java/com/google/protobuf/RopeByteStringTest.java | |
parent | 7139d1eff739682a088ea2c2dbdfef2f108321f8 (diff) | |
download | protobuf-e84893f6768f136cc86e2db69fc1d40ff2be7e3b.tar.gz protobuf-e84893f6768f136cc86e2db69fc1d40ff2be7e3b.tar.bz2 protobuf-e84893f6768f136cc86e2db69fc1d40ff2be7e3b.zip |
perf: String#getBytes(Charset) vs getBytes(String)
Diffstat (limited to 'java/src/test/java/com/google/protobuf/RopeByteStringTest.java')
-rw-r--r-- | java/src/test/java/com/google/protobuf/RopeByteStringTest.java | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/java/src/test/java/com/google/protobuf/RopeByteStringTest.java b/java/src/test/java/com/google/protobuf/RopeByteStringTest.java index 4775f03a..54eb9683 100644 --- a/java/src/test/java/com/google/protobuf/RopeByteStringTest.java +++ b/java/src/test/java/com/google/protobuf/RopeByteStringTest.java @@ -119,6 +119,32 @@ public class RopeByteStringTest extends LiteralByteStringTest { } @Override + public void testCharsetToString() throws UnsupportedEncodingException { + String sourceString = "I love unicode \u1234\u5678 characters"; + ByteString sourceByteString = ByteString.copyFromUtf8(sourceString); + int copies = 250; + + // By building the RopeByteString by concatenating, this is actually a fairly strenuous test. + StringBuilder builder = new StringBuilder(copies * sourceString.length()); + ByteString unicode = ByteString.EMPTY; + for (int i = 0; i < copies; ++i) { + builder.append(sourceString); + unicode = RopeByteString.concatenate(unicode, sourceByteString); + } + String testString = builder.toString(); + + assertEquals(classUnderTest + " from string must have the expected type", + classUnderTest, getActualClassName(unicode)); + String roundTripString = unicode.toString(ByteString.UTF_8); + assertEquals(classUnderTest + " unicode bytes must match", + testString, roundTripString); + ByteString flatString = ByteString.copyFromUtf8(testString); + assertEquals(classUnderTest + " string must equal the flat string", flatString, unicode); + assertEquals(classUnderTest + " string must must have same hashCode as the flat string", + flatString.hashCode(), unicode.hashCode()); + } + + @Override public void testToString_returnsCanonicalEmptyString() throws UnsupportedEncodingException { RopeByteString ropeByteString = RopeByteString.newInstanceForTest(ByteString.EMPTY, ByteString.EMPTY); |