Skip to content

Commit

Permalink
bugFix resolving type mismatch w.r.t DescriptorType (#4463)
Browse files Browse the repository at this point in the history
  • Loading branch information
stschr committed Apr 23, 2024
1 parent e2e4521 commit 0e82824
Show file tree
Hide file tree
Showing 2 changed files with 122 additions and 31 deletions.
4 changes: 2 additions & 2 deletions src/dash/vo/DescriptorType.js
Expand Up @@ -44,7 +44,7 @@ class DescriptorType {
init(data) {
if (data) {
this.schemeIdUri = data.schemeIdUri ? data.schemeIdUri : null;
this.value = data.value ? data.value : null;
this.value = data.value ? data.value.toString() : null;
this.id = data.id ? data.id : null;
// Only add the DVB extensions if they exist
if (data[DashConstants.DVB_URL]) {
Expand All @@ -65,7 +65,7 @@ class DescriptorType {
return (
this.schemeIdUri === entry.schemeIdUri && (
this.value ?
(this.value.match(entry.value)) : // check if provided value matches RegExp
(this.value.toString().match(entry.value)) : // check if provided value matches RegExp
(''.match(entry.value)) // check if RegExp allows absent value
)
);
Expand Down
149 changes: 120 additions & 29 deletions test/unit/test/dash/dash.vo.DescriptorType.js
@@ -1,44 +1,135 @@
import DescriptorType from '../../../../src/dash/vo/DescriptorType.js';

import {expect} from 'chai';
import { expect } from 'chai';

describe('DescriptorType', () => {

it('should be constructed with null values', () => {
const dt = new DescriptorType();
expect(dt).to.deep.equal({
schemeIdUri: null,
value: null,
id: null
describe('Initialization', () => {
it('should be constructed with null values', () => {
const dt = new DescriptorType();
expect(dt).to.deep.equal({
schemeIdUri: null,
value: null,
id: null
});
});
});

it('should initialise with correct base values', () => {
const dt = new DescriptorType();
dt.init({
schemeIdUri: 'testScheme',
value: '1',
it('should initialise with correct base values', () => {
const dt = new DescriptorType();
dt.init({
schemeIdUri: 'testScheme',
value: '1',
});
expect(dt).to.deep.equal({
schemeIdUri: 'testScheme',
value: '1',
id: null
});
});
expect(dt).to.deep.equal({
schemeIdUri: 'testScheme',
value: '1',
id: null

it('should initialise with correct base values and type conversion', () => {
const dt = new DescriptorType();
dt.init({
schemeIdUri: 'testScheme',
value: 1,
});
expect(dt).to.deep.equal({
schemeIdUri: 'testScheme',
value: '1',
id: null
});
});

it('should initialise with known dvb extensions if present', () => {
const dt = new DescriptorType();
dt.init({
schemeIdUri: 'testScheme',
value: '1',
'dvb:url': 'testUrl'
});
expect(dt).to.deep.equal({
schemeIdUri: 'testScheme',
value: '1',
id: null,
dvbUrl: 'testUrl'
});
});
});

it('should initialise with known dvb extensions if present', () => {
const dt = new DescriptorType();
dt.init({
schemeIdUri: 'testScheme',
value: '1',
'dvb:url': 'testUrl'
describe('inArray', () => {
it('should return false array is empty', () => {
const dt = new DescriptorType();
dt.init({
schemeIdUri: 'testScheme',
value: 10
});
const testArray = [];

let ret = dt.inArray(testArray);
expect(ret).to.be.false;
});
expect(dt).to.deep.equal({
schemeIdUri: 'testScheme',
value: '1',
id: null,
dvbUrl: 'testUrl'

it('should find a descriptor if only the schemeIdUri is provided', () => {
const dt = new DescriptorType();
dt.init({
schemeIdUri: 'testScheme',
value: 10
});
const testArray = [
{ schemeIdUri: 'notSupportedTestScheme' },
{ schemeIdUri: 'testScheme' },
{ schemeIdUri: 'notSupported' }
];

let ret = dt.inArray(testArray);
expect(ret).to.be.true;
});
});

it('should not erroneously match a descriptor if different schemeIdUri are provided', () => {
const dt = new DescriptorType();
dt.init({
schemeIdUri: 'testScheme',
value: 10
});
const testArray = [
{ schemeIdUri: 'notSupportedTestScheme' },
{ schemeIdUri: 'notSupported' }
];

let ret = dt.inArray(testArray);
expect(ret).to.be.false;
});

it('should find a descriptor if schemeIdUri and value is provided', () => {
const dt = new DescriptorType();
dt.init({
schemeIdUri: 'testScheme',
value: 2
});
const testArray = [
{ schemeIdUri: 'notSupportedTestScheme', value: '1' },
{ schemeIdUri: 'testScheme', value: '2' },
{ schemeIdUri: 'notSupported', value: '3' }
];

let ret = dt.inArray(testArray);
expect(ret).to.be.true;
});

it('should not find a descriptor if schemeIdUri is provided and value not matches', () => {
const dt = new DescriptorType();
dt.init({
schemeIdUri: 'testScheme',
value: 3
});
const testArray = [
{ schemeIdUri: 'notSupportedTestScheme', value: '1' },
{ schemeIdUri: 'testScheme', value: '1' },
{ schemeIdUri: 'notSupported', value: '1' }
];

let ret = dt.inArray(testArray);
expect(ret).to.be.false;
});
});
});

0 comments on commit 0e82824

Please sign in to comment.