mirror of
https://github.com/samsonjs/media.git
synced 2026-04-12 12:25:47 +00:00
Add overflow tests for sample count to duration conversion methods
These methods were updated to use the new overflow-resistant
`scaleLargeValue` method in 885ddb167e.
PiperOrigin-RevId: 565059609
This commit is contained in:
parent
d111976125
commit
f8b23da7af
1 changed files with 20 additions and 0 deletions
|
|
@ -850,6 +850,26 @@ public class UtilTest {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void durationToSampleCount_doesntOverflowWithLargeDuration() {
|
||||
// Choose a durationUs & sampleRate that will overflow a signed 64-bit integer if they are
|
||||
// multiplied together, but not if the durationUs is converted to seconds first.
|
||||
long sampleCount =
|
||||
Util.durationUsToSampleCount(
|
||||
/* durationUs= */ Long.MAX_VALUE / 100_000, /* sampleRate= */ 192_000);
|
||||
assertThat(sampleCount).isEqualTo(17708874310762L);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sampleCountToDuration_doesntOverflowWithLargeDuration() {
|
||||
// Choose a sampleCount that will overflow a signed 64-bit integer if it is multiplied directly
|
||||
// by C.MICROS_PER_SECOND, but not if it is divided by sampleRate first.
|
||||
long durationUs =
|
||||
Util.sampleCountToDurationUs(
|
||||
/* sampleCount= */ Long.MAX_VALUE / 100_000, /* sampleRate= */ 192_000);
|
||||
assertThat(durationUs).isEqualTo(480383960252848L);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseXsDuration_returnsParsedDurationInMillis() {
|
||||
assertThat(parseXsDuration("PT150.279S")).isEqualTo(150279L);
|
||||
|
|
|
|||
Loading…
Reference in a new issue