Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
P
protobuf
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
protobuf
Commits
a32a1a76
Commit
a32a1a76
authored
Nov 27, 2014
by
Daniel Martin
Committed by
Daniel Martin
Nov 27, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add tests for other ByteString subclasses
parent
5ff8dc8e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
0 deletions
+37
-0
BoundedByteStringTest.java
.../test/java/com/google/protobuf/BoundedByteStringTest.java
+19
-0
RopeByteStringTest.java
...src/test/java/com/google/protobuf/RopeByteStringTest.java
+18
-0
No files found.
java/src/test/java/com/google/protobuf/BoundedByteStringTest.java
View file @
a32a1a76
...
...
@@ -30,8 +30,14 @@
package
com
.
google
.
protobuf
;
import
java.io.ByteArrayInputStream
;
import
java.io.ByteArrayOutputStream
;
import
java.io.InputStream
;
import
java.io.ObjectInputStream
;
import
java.io.ObjectOutputStream
;
import
java.io.UnsupportedEncodingException
;
/**
* This class tests {@link BoundedByteString}, which extends {@link LiteralByteString},
* by inheriting the tests from {@link LiteralByteStringTest}. The only method which
...
...
@@ -65,4 +71,17 @@ public class BoundedByteStringTest extends LiteralByteStringTest {
assertEquals
(
classUnderTest
+
" unicode bytes must match"
,
testString
.
substring
(
2
,
testString
.
length
()
-
6
),
roundTripString
);
}
public
void
testJavaSerialization
()
throws
Exception
{
ByteArrayOutputStream
out
=
new
ByteArrayOutputStream
();
ObjectOutputStream
oos
=
new
ObjectOutputStream
(
out
);
oos
.
writeObject
(
stringUnderTest
);
oos
.
close
();
byte
[]
pickled
=
out
.
toByteArray
();
InputStream
in
=
new
ByteArrayInputStream
(
pickled
);
ObjectInputStream
ois
=
new
ObjectInputStream
(
in
);
Object
o
=
ois
.
readObject
();
assertTrue
(
"Didn't get a ByteString back"
,
o
instanceof
ByteString
);
assertEquals
(
"Should get an equal ByteString back"
,
stringUnderTest
,
o
);
}
}
java/src/test/java/com/google/protobuf/RopeByteStringTest.java
View file @
a32a1a76
...
...
@@ -30,6 +30,11 @@
package
com
.
google
.
protobuf
;
import
java.io.ByteArrayInputStream
;
import
java.io.ByteArrayOutputStream
;
import
java.io.InputStream
;
import
java.io.ObjectInputStream
;
import
java.io.ObjectOutputStream
;
import
java.io.UnsupportedEncodingException
;
import
java.util.Arrays
;
import
java.util.Iterator
;
...
...
@@ -112,4 +117,17 @@ public class RopeByteStringTest extends LiteralByteStringTest {
assertEquals
(
classUnderTest
+
" string must must have same hashCode as the flat string"
,
flatString
.
hashCode
(),
unicode
.
hashCode
());
}
public
void
testJavaSerialization
()
throws
Exception
{
ByteArrayOutputStream
out
=
new
ByteArrayOutputStream
();
ObjectOutputStream
oos
=
new
ObjectOutputStream
(
out
);
oos
.
writeObject
(
stringUnderTest
);
oos
.
close
();
byte
[]
pickled
=
out
.
toByteArray
();
InputStream
in
=
new
ByteArrayInputStream
(
pickled
);
ObjectInputStream
ois
=
new
ObjectInputStream
(
in
);
Object
o
=
ois
.
readObject
();
assertTrue
(
"Didn't get a ByteString back"
,
o
instanceof
ByteString
);
assertEquals
(
"Should get an equal ByteString back"
,
stringUnderTest
,
o
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment