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/RopeByteStringSubstringTest.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/RopeByteStringSubstringTest.java')
-rw-r--r-- | java/src/test/java/com/google/protobuf/RopeByteStringSubstringTest.java | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/java/src/test/java/com/google/protobuf/RopeByteStringSubstringTest.java b/java/src/test/java/com/google/protobuf/RopeByteStringSubstringTest.java index 8106201d..43872d1d 100644 --- a/java/src/test/java/com/google/protobuf/RopeByteStringSubstringTest.java +++ b/java/src/test/java/com/google/protobuf/RopeByteStringSubstringTest.java @@ -94,4 +94,34 @@ public class RopeByteStringSubstringTest extends LiteralByteStringTest { assertEquals(classUnderTest + " string must must have same hashCode as the flat string", flatString.hashCode(), unicode.hashCode()); } + + @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(); + + // Do the substring part + testString = testString.substring(2, testString.length() - 6); + unicode = unicode.substring(2, unicode.size() - 6); + + 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()); + } } |