Skip to content

Commit

Permalink
test: Fix FakeSegmentIndex implementation (#7197)
Browse files Browse the repository at this point in the history
Related to #7184
  • Loading branch information
avelad authored Aug 23, 2024
1 parent 7e0f261 commit 230bd90
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
3 changes: 3 additions & 0 deletions test/media/streaming_engine_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -4452,6 +4452,9 @@ describe('StreamingEngine', () => {
altSegmentIndex.find.and.callFake(
(time) => baseStream.segmentIndex.find(time));

altSegmentIndex.getNumReferences.and.callFake(
() => baseStream.segmentIndex.getNumReferences());

altSegmentIndex.get.and.callFake((pos) => {
const ref = baseStream.segmentIndex.get(pos);

Expand Down
7 changes: 7 additions & 0 deletions test/test/util/simple_fakes.js
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,10 @@ shaka.test.FakeSegmentIndex = class {
/** @type {!jasmine.Spy} */
this.release = jasmine.createSpy('release');

/** @type {!jasmine.Spy} */
this.getNumReferences =
jasmine.createSpy('getNumReferences').and.returnValue(0);

/** @type {!jasmine.Spy} */
this.find = jasmine.createSpy('find').and.returnValue(null);

Expand Down Expand Up @@ -482,6 +486,9 @@ shaka.test.FakeSegmentIndex = class {
this.getIteratorForTime = jasmine.createSpy('getIteratorForTime')
.and.callFake((time) => {
let nextPosition = this.find(time);
if (nextPosition == null) {
nextPosition = this.getNumReferences();
}

return {
next: () => {
Expand Down
22 changes: 22 additions & 0 deletions test/test/util/streaming_engine_util.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,24 @@ shaka.test.StreamingEngineUtil = class {
secondaryAudioVariant = false) {
const Util = shaka.test.Util;

/**
* @param {string} type
* @return {number}
*/
const getNumReferences = (type) => {
let totalReferences = 0;
for (let i = 0; i < periodStartTimes.length; ++i) {
const startTime = periodStartTimes[i];
const nextStartTime = i < periodStartTimes.length - 1 ?
periodStartTimes[i + 1] :
presentationDuration;
const periodDuration = nextStartTime - startTime;
const numSegments = Math.ceil(periodDuration / segmentDurations[type]);
totalReferences += numSegments;
}
return totalReferences;
};

/**
* @param {string} type
* @param {number} time
Expand Down Expand Up @@ -374,6 +392,8 @@ shaka.test.StreamingEngineUtil = class {

const ContentType = shaka.util.ManifestParserUtils.ContentType;
const segmentIndex = new shaka.test.FakeSegmentIndex();
segmentIndex.getNumReferences.and.callFake(
() => getNumReferences(ContentType.AUDIO));
segmentIndex.find.and.callFake((time) => find(ContentType.AUDIO, time));
segmentIndex.get.and.callFake((pos) => {
return get(ContentType.AUDIO, pos,
Expand Down Expand Up @@ -420,6 +440,8 @@ shaka.test.StreamingEngineUtil = class {
}

const segmentIndex = new shaka.test.FakeSegmentIndex();
segmentIndex.getNumReferences.and.callFake(
() => getNumReferences(type));
segmentIndex.find.and.callFake((time) => find(type, time));
segmentIndex.get.and.callFake((pos) => {
return get(type, pos, stream.mimeType, stream.codecs);
Expand Down

0 comments on commit 230bd90

Please sign in to comment.