Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
SDK
/
exoplayer
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
2f1eb816
authored
Feb 09, 2022
by
kimvde
Committed by
Ian Baker
Feb 17, 2022
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Transformer: format test analysis file to JSON
PiperOrigin-RevId: 427469350
parent
1e2345cf
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
32 deletions
library/transformer/src/androidTest/java/com/google/android/exoplayer2/transformer/AndroidTestUtil.java
library/transformer/src/androidTest/java/com/google/android/exoplayer2/transformer/AndroidTestUtil.java
View file @
2f1eb816
...
@@ -32,6 +32,8 @@ import java.io.IOException;
...
@@ -32,6 +32,8 @@ import java.io.IOException;
import
java.util.concurrent.CountDownLatch
;
import
java.util.concurrent.CountDownLatch
;
import
java.util.concurrent.atomic.AtomicReference
;
import
java.util.concurrent.atomic.AtomicReference
;
import
org.checkerframework.checker.nullness.compatqual.NullableType
;
import
org.checkerframework.checker.nullness.compatqual.NullableType
;
import
org.json.JSONException
;
import
org.json.JSONObject
;
/** Utilities for instrumentation tests. */
/** Utilities for instrumentation tests. */
public
final
class
AndroidTestUtil
{
public
final
class
AndroidTestUtil
{
...
@@ -107,43 +109,21 @@ public final class AndroidTestUtil {
...
@@ -107,43 +109,21 @@ public final class AndroidTestUtil {
return
result
;
return
result
;
}
}
private
static
void
writeResultToFile
(
Context
context
,
String
testId
,
TransformationResult
result
)
private
static
void
writeResultToFile
(
throws
IOException
{
Context
context
,
String
testId
,
TransformationResult
transformationResult
)
throws
IOException
,
JSONException
{
File
analysisFile
=
createExternalCacheFile
(
context
,
/* fileName= */
testId
+
"-result.txt"
);
File
analysisFile
=
createExternalCacheFile
(
context
,
/* fileName= */
testId
+
"-result.txt"
);
String
analysisContent
=
new
JSONObject
()
.
put
(
"testId"
,
testId
)
.
put
(
"device"
,
getDeviceJson
())
.
put
(
"transformationResult"
,
getTransformationResultJson
(
transformationResult
))
.
toString
(
/* indentSpaces= */
2
);
try
(
FileWriter
fileWriter
=
new
FileWriter
(
analysisFile
))
{
try
(
FileWriter
fileWriter
=
new
FileWriter
(
analysisFile
))
{
String
fileContents
=
fileWriter
.
write
(
analysisContent
);
"test="
+
testId
+
", "
+
getFormattedResult
(
result
)
+
", deviceFingerprint="
+
Build
.
FINGERPRINT
+
", deviceBrand="
+
Build
.
MANUFACTURER
+
", deviceModel="
+
Build
.
MODEL
+
", sdkVersion="
+
Build
.
VERSION
.
SDK_INT
;
fileWriter
.
write
(
fileContents
);
}
}
}
}
/** Formats a {@link TransformationResult} into a comma separated String. */
public
static
String
getFormattedResult
(
TransformationResult
result
)
{
String
analysis
=
""
;
if
(
result
.
fileSizeBytes
!=
C
.
LENGTH_UNSET
)
{
analysis
+=
"fileSizeBytes="
+
result
.
fileSizeBytes
;
}
if
(
result
.
averageAudioBitrate
!=
C
.
RATE_UNSET_INT
)
{
analysis
+=
", averageAudioBitrate="
+
result
.
averageAudioBitrate
;
}
if
(
result
.
averageVideoBitrate
!=
C
.
RATE_UNSET_INT
)
{
analysis
+=
", averageVideoBitrate="
+
result
.
averageVideoBitrate
;
}
return
analysis
;
}
private
static
File
createExternalCacheFile
(
Context
context
,
String
fileName
)
throws
IOException
{
private
static
File
createExternalCacheFile
(
Context
context
,
String
fileName
)
throws
IOException
{
File
file
=
new
File
(
context
.
getExternalCacheDir
(),
fileName
);
File
file
=
new
File
(
context
.
getExternalCacheDir
(),
fileName
);
checkState
(!
file
.
exists
()
||
file
.
delete
(),
"Could not delete file: "
+
file
.
getAbsolutePath
());
checkState
(!
file
.
exists
()
||
file
.
delete
(),
"Could not delete file: "
+
file
.
getAbsolutePath
());
...
@@ -151,5 +131,28 @@ public final class AndroidTestUtil {
...
@@ -151,5 +131,28 @@ public final class AndroidTestUtil {
return
file
;
return
file
;
}
}
private
static
JSONObject
getDeviceJson
()
throws
JSONException
{
return
new
JSONObject
()
.
put
(
"manufacturer"
,
Build
.
MANUFACTURER
)
.
put
(
"model"
,
Build
.
MODEL
)
.
put
(
"sdkVersion"
,
Build
.
VERSION
.
SDK_INT
)
.
put
(
"fingerprint"
,
Build
.
FINGERPRINT
);
}
private
static
JSONObject
getTransformationResultJson
(
TransformationResult
transformationResult
)
throws
JSONException
{
JSONObject
transformationResultJson
=
new
JSONObject
();
if
(
transformationResult
.
fileSizeBytes
!=
C
.
LENGTH_UNSET
)
{
transformationResultJson
.
put
(
"fileSizeBytes"
,
transformationResult
.
fileSizeBytes
);
}
if
(
transformationResult
.
averageAudioBitrate
!=
C
.
RATE_UNSET_INT
)
{
transformationResultJson
.
put
(
"averageAudioBitrate"
,
transformationResult
.
averageAudioBitrate
);
}
if
(
transformationResult
.
averageVideoBitrate
!=
C
.
RATE_UNSET_INT
)
{
transformationResultJson
.
put
(
"averageVideoBitrate"
,
transformationResult
.
averageVideoBitrate
);
}
return
transformationResultJson
;
}
private
AndroidTestUtil
()
{}
private
AndroidTestUtil
()
{}
}
}
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