Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
platform_frameworks_base-old
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Farzin Kazemzadeh
platform_frameworks_base-old
Commits
1a6f5550
Commit
1a6f5550
authored
9 months ago
by
Peter Li
Committed by
Android (Google) Code Review
9 months ago
Browse files
Options
Downloads
Plain Diff
Merge "Add unit test to test data overflow when using BinaryXmlSerializer" into udc-dev
parents
ee8f9d77
eebe3b8b
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
core/tests/coretests/src/android/util/BinaryXmlTest.java
+50
-0
50 additions, 0 deletions
core/tests/coretests/src/android/util/BinaryXmlTest.java
with
50 additions
and
0 deletions
core/tests/coretests/src/android/util/BinaryXmlTest.java
+
50
−
0
View file @
1a6f5550
...
...
@@ -24,6 +24,8 @@ import static android.util.XmlTest.doVerifyRead;
import
static
android
.
util
.
XmlTest
.
doVerifyWrite
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertThrows
;
import
static
org
.
junit
.
Assert
.
fail
;
import
static
org
.
xmlpull
.
v1
.
XmlPullParser
.
START_TAG
;
import
android.os.PersistableBundle
;
...
...
@@ -41,12 +43,15 @@ import java.io.ByteArrayOutputStream;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.OutputStream
;
import
java.nio.charset.StandardCharsets
;
@RunWith
(
AndroidJUnit4
.
class
)
public
class
BinaryXmlTest
{
private
static
final
int
MAX_UNSIGNED_SHORT
=
65_535
;
/**
* Verify that we can write and read large numbers of interned
* {@link String} values.
...
...
@@ -170,4 +175,49 @@ public class BinaryXmlTest {
}
}
}
@Test
public
void
testAttributeBytes_BinaryDataOverflow
()
throws
Exception
{
final
TypedXmlSerializer
out
=
Xml
.
newBinarySerializer
();
final
ByteArrayOutputStream
os
=
new
ByteArrayOutputStream
();
out
.
setOutput
(
os
,
StandardCharsets
.
UTF_8
.
name
());
final
byte
[]
testBytes
=
new
byte
[
MAX_UNSIGNED_SHORT
+
1
];
assertThrows
(
IOException
.
class
,
()
->
out
.
attributeBytesHex
(
/* namespace */
null
,
/* name */
"attributeBytesHex"
,
testBytes
));
assertThrows
(
IOException
.
class
,
()
->
out
.
attributeBytesBase64
(
/* namespace */
null
,
/* name */
"attributeBytesBase64"
,
testBytes
));
}
@Test
public
void
testAttributeBytesHex_MaximumBinaryData
()
throws
Exception
{
final
TypedXmlSerializer
out
=
Xml
.
newBinarySerializer
();
final
ByteArrayOutputStream
os
=
new
ByteArrayOutputStream
();
out
.
setOutput
(
os
,
StandardCharsets
.
UTF_8
.
name
());
final
byte
[]
testBytes
=
new
byte
[
MAX_UNSIGNED_SHORT
];
try
{
out
.
attributeBytesHex
(
/* namespace */
null
,
/* name */
"attributeBytesHex"
,
testBytes
);
}
catch
(
Exception
e
)
{
fail
(
"testAttributeBytesHex fails with exception: "
+
e
.
toString
());
}
}
@Test
public
void
testAttributeBytesBase64_MaximumBinaryData
()
throws
Exception
{
final
TypedXmlSerializer
out
=
Xml
.
newBinarySerializer
();
final
ByteArrayOutputStream
os
=
new
ByteArrayOutputStream
();
out
.
setOutput
(
os
,
StandardCharsets
.
UTF_8
.
name
());
final
byte
[]
testBytes
=
new
byte
[
MAX_UNSIGNED_SHORT
];
try
{
out
.
attributeBytesBase64
(
/* namespace */
null
,
/* name */
"attributeBytesBase64"
,
testBytes
);
}
catch
(
Exception
e
)
{
fail
(
"testAttributeBytesBase64 fails with exception: "
+
e
.
toString
());
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment