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
f497bb96
authored
Aug 02, 2019
by
olly
Committed by
Oliver Woodman
Aug 02, 2019
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Move DefaultOggSeeker tests into a single class
PiperOrigin-RevId: 261320318
parent
1da5689e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
136 additions
and
163 deletions
library/core/src/test/java/com/google/android/exoplayer2/extractor/ogg/DefaultOggSeekerTest.java
library/core/src/test/java/com/google/android/exoplayer2/extractor/ogg/DefaultOggSeekerUtilMethodsTest.java
library/core/src/test/java/com/google/android/exoplayer2/extractor/ogg/DefaultOggSeekerTest.java
View file @
f497bb96
...
@@ -20,8 +20,12 @@ import static org.junit.Assert.fail;
...
@@ -20,8 +20,12 @@ import static org.junit.Assert.fail;
import
androidx.test.ext.junit.runners.AndroidJUnit4
;
import
androidx.test.ext.junit.runners.AndroidJUnit4
;
import
com.google.android.exoplayer2.C
;
import
com.google.android.exoplayer2.C
;
import
com.google.android.exoplayer2.extractor.ExtractorInput
;
import
com.google.android.exoplayer2.testutil.FakeExtractorInput
;
import
com.google.android.exoplayer2.testutil.FakeExtractorInput
;
import
com.google.android.exoplayer2.testutil.OggTestData
;
import
com.google.android.exoplayer2.testutil.TestUtil
;
import
com.google.android.exoplayer2.util.ParsableByteArray
;
import
com.google.android.exoplayer2.util.ParsableByteArray
;
import
java.io.EOFException
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.util.Random
;
import
java.util.Random
;
import
org.junit.Test
;
import
org.junit.Test
;
...
@@ -31,6 +35,8 @@ import org.junit.runner.RunWith;
...
@@ -31,6 +35,8 @@ import org.junit.runner.RunWith;
@RunWith
(
AndroidJUnit4
.
class
)
@RunWith
(
AndroidJUnit4
.
class
)
public
final
class
DefaultOggSeekerTest
{
public
final
class
DefaultOggSeekerTest
{
private
final
Random
random
=
new
Random
(
0
);
@Test
@Test
public
void
testSetupWithUnsetEndPositionFails
()
{
public
void
testSetupWithUnsetEndPositionFails
()
{
try
{
try
{
...
@@ -55,6 +61,95 @@ public final class DefaultOggSeekerTest {
...
@@ -55,6 +61,95 @@ public final class DefaultOggSeekerTest {
}
}
}
}
@Test
public
void
testSkipToNextPage
()
throws
Exception
{
FakeExtractorInput
extractorInput
=
OggTestData
.
createInput
(
TestUtil
.
joinByteArrays
(
TestUtil
.
buildTestData
(
4000
,
random
),
new
byte
[]
{
'O'
,
'g'
,
'g'
,
'S'
},
TestUtil
.
buildTestData
(
4000
,
random
)),
false
);
skipToNextPage
(
extractorInput
);
assertThat
(
extractorInput
.
getPosition
()).
isEqualTo
(
4000
);
}
@Test
public
void
testSkipToNextPageOverlap
()
throws
Exception
{
FakeExtractorInput
extractorInput
=
OggTestData
.
createInput
(
TestUtil
.
joinByteArrays
(
TestUtil
.
buildTestData
(
2046
,
random
),
new
byte
[]
{
'O'
,
'g'
,
'g'
,
'S'
},
TestUtil
.
buildTestData
(
4000
,
random
)),
false
);
skipToNextPage
(
extractorInput
);
assertThat
(
extractorInput
.
getPosition
()).
isEqualTo
(
2046
);
}
@Test
public
void
testSkipToNextPageInputShorterThanPeekLength
()
throws
Exception
{
FakeExtractorInput
extractorInput
=
OggTestData
.
createInput
(
TestUtil
.
joinByteArrays
(
new
byte
[]
{
'x'
,
'O'
,
'g'
,
'g'
,
'S'
}),
false
);
skipToNextPage
(
extractorInput
);
assertThat
(
extractorInput
.
getPosition
()).
isEqualTo
(
1
);
}
@Test
public
void
testSkipToNextPageNoMatch
()
throws
Exception
{
FakeExtractorInput
extractorInput
=
OggTestData
.
createInput
(
new
byte
[]
{
'g'
,
'g'
,
'S'
,
'O'
,
'g'
,
'g'
},
false
);
try
{
skipToNextPage
(
extractorInput
);
fail
();
}
catch
(
EOFException
e
)
{
// expected
}
}
@Test
public
void
testReadGranuleOfLastPage
()
throws
IOException
,
InterruptedException
{
FakeExtractorInput
input
=
OggTestData
.
createInput
(
TestUtil
.
joinByteArrays
(
TestUtil
.
buildTestData
(
100
,
random
),
OggTestData
.
buildOggHeader
(
0x00
,
20000
,
66
,
3
),
TestUtil
.
createByteArray
(
254
,
254
,
254
),
// laces
TestUtil
.
buildTestData
(
3
*
254
,
random
),
OggTestData
.
buildOggHeader
(
0x00
,
40000
,
67
,
3
),
TestUtil
.
createByteArray
(
254
,
254
,
254
),
// laces
TestUtil
.
buildTestData
(
3
*
254
,
random
),
OggTestData
.
buildOggHeader
(
0x05
,
60000
,
68
,
3
),
TestUtil
.
createByteArray
(
254
,
254
,
254
),
// laces
TestUtil
.
buildTestData
(
3
*
254
,
random
)),
false
);
assertReadGranuleOfLastPage
(
input
,
60000
);
}
@Test
public
void
testReadGranuleOfLastPageAfterLastHeader
()
throws
IOException
,
InterruptedException
{
FakeExtractorInput
input
=
OggTestData
.
createInput
(
TestUtil
.
buildTestData
(
100
,
random
),
false
);
try
{
assertReadGranuleOfLastPage
(
input
,
60000
);
fail
();
}
catch
(
EOFException
e
)
{
// Ignored.
}
}
@Test
public
void
testReadGranuleOfLastPageWithUnboundedLength
()
throws
IOException
,
InterruptedException
{
FakeExtractorInput
input
=
OggTestData
.
createInput
(
new
byte
[
0
],
true
);
try
{
assertReadGranuleOfLastPage
(
input
,
60000
);
fail
();
}
catch
(
IllegalArgumentException
e
)
{
// Ignored.
}
}
private
void
testSeeking
(
Random
random
)
throws
IOException
,
InterruptedException
{
private
void
testSeeking
(
Random
random
)
throws
IOException
,
InterruptedException
{
OggTestFile
testFile
=
OggTestFile
.
generate
(
random
,
1000
);
OggTestFile
testFile
=
OggTestFile
.
generate
(
random
,
1000
);
FakeExtractorInput
input
=
new
FakeExtractorInput
.
Builder
().
setData
(
testFile
.
data
).
build
();
FakeExtractorInput
input
=
new
FakeExtractorInput
.
Builder
().
setData
(
testFile
.
data
).
build
();
...
@@ -130,7 +225,47 @@ public final class DefaultOggSeekerTest {
...
@@ -130,7 +225,47 @@ public final class DefaultOggSeekerTest {
}
}
}
}
private
long
seekTo
(
private
static
void
skipToNextPage
(
ExtractorInput
extractorInput
)
throws
IOException
,
InterruptedException
{
DefaultOggSeeker
oggSeeker
=
new
DefaultOggSeeker
(
/* streamReader= */
new
FlacReader
(),
/* payloadStartPosition= */
0
,
/* payloadEndPosition= */
extractorInput
.
getLength
(),
/* firstPayloadPageSize= */
1
,
/* firstPayloadPageGranulePosition= */
2
,
/* firstPayloadPageIsLastPage= */
false
);
while
(
true
)
{
try
{
oggSeeker
.
skipToNextPage
(
extractorInput
);
break
;
}
catch
(
FakeExtractorInput
.
SimulatedIOException
e
)
{
/* ignored */
}
}
}
private
static
void
assertReadGranuleOfLastPage
(
FakeExtractorInput
input
,
int
expected
)
throws
IOException
,
InterruptedException
{
DefaultOggSeeker
oggSeeker
=
new
DefaultOggSeeker
(
/* streamReader= */
new
FlacReader
(),
/* payloadStartPosition= */
0
,
/* payloadEndPosition= */
input
.
getLength
(),
/* firstPayloadPageSize= */
1
,
/* firstPayloadPageGranulePosition= */
2
,
/* firstPayloadPageIsLastPage= */
false
);
while
(
true
)
{
try
{
assertThat
(
oggSeeker
.
readGranuleOfLastPage
(
input
)).
isEqualTo
(
expected
);
break
;
}
catch
(
FakeExtractorInput
.
SimulatedIOException
e
)
{
// Ignored.
}
}
}
private
static
long
seekTo
(
FakeExtractorInput
input
,
DefaultOggSeeker
oggSeeker
,
long
targetGranule
,
int
initialPosition
)
FakeExtractorInput
input
,
DefaultOggSeeker
oggSeeker
,
long
targetGranule
,
int
initialPosition
)
throws
IOException
,
InterruptedException
{
throws
IOException
,
InterruptedException
{
long
nextSeekPosition
=
initialPosition
;
long
nextSeekPosition
=
initialPosition
;
...
...
library/core/src/test/java/com/google/android/exoplayer2/extractor/ogg/DefaultOggSeekerUtilMethodsTest.java
deleted
100644 → 0
View file @
1da5689e
/*
* Copyright (C) 2016 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
com
.
google
.
android
.
exoplayer2
.
extractor
.
ogg
;
import
static
com
.
google
.
common
.
truth
.
Truth
.
assertThat
;
import
static
org
.
junit
.
Assert
.
fail
;
import
androidx.test.ext.junit.runners.AndroidJUnit4
;
import
com.google.android.exoplayer2.extractor.ExtractorInput
;
import
com.google.android.exoplayer2.testutil.FakeExtractorInput
;
import
com.google.android.exoplayer2.testutil.OggTestData
;
import
com.google.android.exoplayer2.testutil.TestUtil
;
import
java.io.EOFException
;
import
java.io.IOException
;
import
java.util.Random
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
/** Unit test for {@link DefaultOggSeeker} utility methods. */
@RunWith
(
AndroidJUnit4
.
class
)
public
final
class
DefaultOggSeekerUtilMethodsTest
{
private
final
Random
random
=
new
Random
(
0
);
@Test
public
void
testSkipToNextPage
()
throws
Exception
{
FakeExtractorInput
extractorInput
=
OggTestData
.
createInput
(
TestUtil
.
joinByteArrays
(
TestUtil
.
buildTestData
(
4000
,
random
),
new
byte
[]
{
'O'
,
'g'
,
'g'
,
'S'
},
TestUtil
.
buildTestData
(
4000
,
random
)
),
false
);
skipToNextPage
(
extractorInput
);
assertThat
(
extractorInput
.
getPosition
()).
isEqualTo
(
4000
);
}
@Test
public
void
testSkipToNextPageOverlap
()
throws
Exception
{
FakeExtractorInput
extractorInput
=
OggTestData
.
createInput
(
TestUtil
.
joinByteArrays
(
TestUtil
.
buildTestData
(
2046
,
random
),
new
byte
[]
{
'O'
,
'g'
,
'g'
,
'S'
},
TestUtil
.
buildTestData
(
4000
,
random
)
),
false
);
skipToNextPage
(
extractorInput
);
assertThat
(
extractorInput
.
getPosition
()).
isEqualTo
(
2046
);
}
@Test
public
void
testSkipToNextPageInputShorterThanPeekLength
()
throws
Exception
{
FakeExtractorInput
extractorInput
=
OggTestData
.
createInput
(
TestUtil
.
joinByteArrays
(
new
byte
[]
{
'x'
,
'O'
,
'g'
,
'g'
,
'S'
}
),
false
);
skipToNextPage
(
extractorInput
);
assertThat
(
extractorInput
.
getPosition
()).
isEqualTo
(
1
);
}
@Test
public
void
testSkipToNextPageNoMatch
()
throws
Exception
{
FakeExtractorInput
extractorInput
=
OggTestData
.
createInput
(
new
byte
[]
{
'g'
,
'g'
,
'S'
,
'O'
,
'g'
,
'g'
},
false
);
try
{
skipToNextPage
(
extractorInput
);
fail
();
}
catch
(
EOFException
e
)
{
// expected
}
}
private
static
void
skipToNextPage
(
ExtractorInput
extractorInput
)
throws
IOException
,
InterruptedException
{
DefaultOggSeeker
oggSeeker
=
new
DefaultOggSeeker
(
/* streamReader= */
new
FlacReader
(),
/* payloadStartPosition= */
0
,
/* payloadEndPosition= */
extractorInput
.
getLength
(),
/* firstPayloadPageSize= */
1
,
/* firstPayloadPageGranulePosition= */
2
,
/* firstPayloadPageIsLastPage= */
false
);
while
(
true
)
{
try
{
oggSeeker
.
skipToNextPage
(
extractorInput
);
break
;
}
catch
(
FakeExtractorInput
.
SimulatedIOException
e
)
{
/* ignored */
}
}
}
@Test
public
void
testReadGranuleOfLastPage
()
throws
IOException
,
InterruptedException
{
FakeExtractorInput
input
=
OggTestData
.
createInput
(
TestUtil
.
joinByteArrays
(
TestUtil
.
buildTestData
(
100
,
random
),
OggTestData
.
buildOggHeader
(
0x00
,
20000
,
66
,
3
),
TestUtil
.
createByteArray
(
254
,
254
,
254
),
// laces
TestUtil
.
buildTestData
(
3
*
254
,
random
),
OggTestData
.
buildOggHeader
(
0x00
,
40000
,
67
,
3
),
TestUtil
.
createByteArray
(
254
,
254
,
254
),
// laces
TestUtil
.
buildTestData
(
3
*
254
,
random
),
OggTestData
.
buildOggHeader
(
0x05
,
60000
,
68
,
3
),
TestUtil
.
createByteArray
(
254
,
254
,
254
),
// laces
TestUtil
.
buildTestData
(
3
*
254
,
random
)
),
false
);
assertReadGranuleOfLastPage
(
input
,
60000
);
}
@Test
public
void
testReadGranuleOfLastPageAfterLastHeader
()
throws
IOException
,
InterruptedException
{
FakeExtractorInput
input
=
OggTestData
.
createInput
(
TestUtil
.
buildTestData
(
100
,
random
),
false
);
try
{
assertReadGranuleOfLastPage
(
input
,
60000
);
fail
();
}
catch
(
EOFException
e
)
{
// Ignored.
}
}
@Test
public
void
testReadGranuleOfLastPageWithUnboundedLength
()
throws
IOException
,
InterruptedException
{
FakeExtractorInput
input
=
OggTestData
.
createInput
(
new
byte
[
0
],
true
);
try
{
assertReadGranuleOfLastPage
(
input
,
60000
);
fail
();
}
catch
(
IllegalArgumentException
e
)
{
// Ignored.
}
}
private
void
assertReadGranuleOfLastPage
(
FakeExtractorInput
input
,
int
expected
)
throws
IOException
,
InterruptedException
{
DefaultOggSeeker
oggSeeker
=
new
DefaultOggSeeker
(
/* streamReader= */
new
FlacReader
(),
/* payloadStartPosition= */
0
,
/* payloadEndPosition= */
input
.
getLength
(),
/* firstPayloadPageSize= */
1
,
/* firstPayloadPageGranulePosition= */
2
,
/* firstPayloadPageIsLastPage= */
false
);
while
(
true
)
{
try
{
assertThat
(
oggSeeker
.
readGranuleOfLastPage
(
input
)).
isEqualTo
(
expected
);
break
;
}
catch
(
FakeExtractorInput
.
SimulatedIOException
e
)
{
// Ignored.
}
}
}
}
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