| 1 |
/* eslint-disable no-unused-vars */ |
| 2 |
const { |
| 3 |
ProfileConstrainedBaseline, |
| 4 |
ProfileBaseline, |
| 5 |
ProfileMain, |
| 6 |
ProfileConstrainedHigh, |
| 7 |
ProfileHigh, |
| 8 |
Level1_b, |
| 9 |
Level1, |
| 10 |
Level1_1, |
| 11 |
Level1_2, |
| 12 |
Level1_3, |
| 13 |
Level2, |
| 14 |
Level2_1, |
| 15 |
Level2_2, |
| 16 |
Level3, |
| 17 |
Level3_1, |
| 18 |
Level3_2, |
| 19 |
Level4, |
| 20 |
Level4_1, |
| 21 |
Level4_2, |
| 22 |
Level5, |
| 23 |
Level5_1, |
| 24 |
Level5_2, |
| 25 |
ProfileLevelId, |
| 26 |
parseProfileLevelId, |
| 27 |
profileLevelIdToString, |
| 28 |
parseSdpProfileLevelId, |
| 29 |
isSameProfile, |
| 30 |
generateProfileLevelIdForAnswer |
| 31 |
} = require('../'); |
| 32 |
/* eslint-enable no-unused-vars */ |
| 33 |
|
| 34 |
test('TestParsingInvalid', () => |
| 35 |
{ |
| 36 |
// Malformed strings. |
| 37 |
expect(parseProfileLevelId()).toBeNull(); |
| 38 |
expect(parseProfileLevelId('')).toBeNull(); |
| 39 |
expect(parseProfileLevelId(' 42e01f')).toBeNull(); |
| 40 |
expect(parseProfileLevelId('4242e01f')).toBeNull(); |
| 41 |
expect(parseProfileLevelId('e01f')).toBeNull(); |
| 42 |
expect(parseProfileLevelId('gggggg')).toBeNull(); |
| 43 |
|
| 44 |
// Invalid level. |
| 45 |
expect(parseProfileLevelId('42e000')).toBeNull(); |
| 46 |
expect(parseProfileLevelId('42e00f')).toBeNull(); |
| 47 |
expect(parseProfileLevelId('42e0ff')).toBeNull(); |
| 48 |
|
| 49 |
// Invalid profile. |
| 50 |
expect(parseProfileLevelId('42e11f')).toBeNull(); |
| 51 |
expect(parseProfileLevelId('58601f')).toBeNull(); |
| 52 |
expect(parseProfileLevelId('64e01f')).toBeNull(); |
| 53 |
}); |
| 54 |
|
| 55 |
test('TestParsingLevel', () => |
| 56 |
{ |
| 57 |
expect(parseProfileLevelId('42e01f').level).toBe(Level3_1); |
| 58 |
expect(parseProfileLevelId('42e00b').level).toBe(Level1_1); |
| 59 |
expect(parseProfileLevelId('42f00b').level).toBe(Level1_b); |
| 60 |
expect(parseProfileLevelId('42C02A').level).toBe(Level4_2); |
| 61 |
expect(parseProfileLevelId('640c34').level).toBe(Level5_2); |
| 62 |
}); |
| 63 |
|
| 64 |
test('TestParsingConstrainedBaseline', () => |
| 65 |
{ |
| 66 |
expect(parseProfileLevelId('42e01f').profile).toBe(ProfileConstrainedBaseline); |
| 67 |
expect(parseProfileLevelId('42C02A').profile).toBe(ProfileConstrainedBaseline); |
| 68 |
expect(parseProfileLevelId('4de01f').profile).toBe(ProfileConstrainedBaseline); |
| 69 |
expect(parseProfileLevelId('58f01f').profile).toBe(ProfileConstrainedBaseline); |
| 70 |
}); |
| 71 |
|
| 72 |
test('TestParsingBaseline', () => |
| 73 |
{ |
| 74 |
expect(parseProfileLevelId('42a01f').profile).toBe(ProfileBaseline); |
| 75 |
expect(parseProfileLevelId('58A01F').profile).toBe(ProfileBaseline); |
| 76 |
}); |
| 77 |
|
| 78 |
test('TestParsingMain', () => |
| 79 |
{ |
| 80 |
expect(parseProfileLevelId('4D401f').profile).toBe(ProfileMain); |
| 81 |
}); |
| 82 |
|
| 83 |
test('TestParsingHigh', () => |
| 84 |
{ |
| 85 |
expect(parseProfileLevelId('64001f').profile).toBe(ProfileHigh); |
| 86 |
}); |
| 87 |
|
| 88 |
test('TestParsingConstrainedHigh', () => |
| 89 |
{ |
| 90 |
expect(parseProfileLevelId('640c1f').profile).toBe(ProfileConstrainedHigh); |
| 91 |
}); |
| 92 |
|
| 93 |
test('TestToString', () => |
| 94 |
{ |
| 95 |
expect( |
| 96 |
profileLevelIdToString(new ProfileLevelId(ProfileConstrainedBaseline, Level3_1)) |
| 97 |
).toBe('42e01f'); |
| 98 |
expect( |
| 99 |
profileLevelIdToString(new ProfileLevelId(ProfileBaseline, Level1)) |
| 100 |
).toBe('42000a'); |
| 101 |
expect( |
| 102 |
profileLevelIdToString(new ProfileLevelId(ProfileMain, Level3_1)) |
| 103 |
).toBe('4d001f'); |
| 104 |
expect( |
| 105 |
profileLevelIdToString(new ProfileLevelId(ProfileConstrainedHigh, Level4_2)) |
| 106 |
).toBe('640c2a'); |
| 107 |
expect( |
| 108 |
profileLevelIdToString(new ProfileLevelId(ProfileHigh, Level4_2)) |
| 109 |
).toBe('64002a'); |
| 110 |
}); |
| 111 |
|
| 112 |
test('TestToStringLevel1b', () => |
| 113 |
{ |
| 114 |
expect( |
| 115 |
profileLevelIdToString(new ProfileLevelId(ProfileConstrainedBaseline, Level1_b)) |
| 116 |
).toBe('42f00b'); |
| 117 |
expect( |
| 118 |
profileLevelIdToString(new ProfileLevelId(ProfileBaseline, Level1_b)) |
| 119 |
).toBe('42100b'); |
| 120 |
expect( |
| 121 |
profileLevelIdToString(new ProfileLevelId(ProfileMain, Level1_b)) |
| 122 |
).toBe('4d100b'); |
| 123 |
}); |
| 124 |
|
| 125 |
test('TestToStringLevel1b', () => |
| 126 |
{ |
| 127 |
expect(profileLevelIdToString(parseProfileLevelId('42e01f'))).toBe('42e01f'); |
| 128 |
expect(profileLevelIdToString(parseProfileLevelId('42E01F'))).toBe('42e01f'); |
| 129 |
expect(profileLevelIdToString(parseProfileLevelId('4d100b'))).toBe('4d100b'); |
| 130 |
expect(profileLevelIdToString(parseProfileLevelId('4D100B'))).toBe('4d100b'); |
| 131 |
expect(profileLevelIdToString(parseProfileLevelId('640c2a'))).toBe('640c2a'); |
| 132 |
expect(profileLevelIdToString(parseProfileLevelId('640C2A'))).toBe('640c2a'); |
| 133 |
}); |
| 134 |
|
| 135 |
test('TestToStringInvalid', () => |
| 136 |
{ |
| 137 |
expect( |
| 138 |
profileLevelIdToString(new ProfileLevelId(ProfileHigh, Level1_b)) |
| 139 |
).toBeNull(); |
| 140 |
expect( |
| 141 |
profileLevelIdToString(new ProfileLevelId(ProfileConstrainedHigh, Level1_b)) |
| 142 |
).toBeNull(); |
| 143 |
expect( |
| 144 |
profileLevelIdToString(new ProfileLevelId(255, Level3_1)) |
| 145 |
).toBeNull(); |
| 146 |
}); |
| 147 |
|
| 148 |
test('TestParseSdpProfileLevelIdEmpty', () => |
| 149 |
{ |
| 150 |
const profile_level_id = parseSdpProfileLevelId(); |
| 151 |
|
| 152 |
expect(profile_level_id).toBeDefined(); |
| 153 |
expect(profile_level_id.profile).toBe(ProfileConstrainedBaseline); |
| 154 |
expect(profile_level_id.level).toBe(Level3_1); |
| 155 |
}); |
| 156 |
|
| 157 |
test('TestParseSdpProfileLevelIdConstrainedHigh', () => |
| 158 |
{ |
| 159 |
const params = { 'profile-level-id': '640c2a' }; |
| 160 |
const profile_level_id = parseSdpProfileLevelId(params); |
| 161 |
|
| 162 |
expect(profile_level_id).toBeDefined(); |
| 163 |
expect(profile_level_id.profile).toBe(ProfileConstrainedHigh); |
| 164 |
expect(profile_level_id.level).toBe(Level4_2); |
| 165 |
}); |
| 166 |
|
| 167 |
test('TestParseSdpProfileLevelIdInvalid', () => |
| 168 |
{ |
| 169 |
const params = { 'profile-level-id': 'foobar' }; |
| 170 |
|
| 171 |
expect(parseSdpProfileLevelId(params)).toBeNull(); |
| 172 |
}); |
| 173 |
|
| 174 |
test('TestIsSameProfile', () => |
| 175 |
{ |
| 176 |
expect( |
| 177 |
isSameProfile({ foo: 'foo' }, { bar: 'bar' }) |
| 178 |
).toBe(true); |
| 179 |
expect( |
| 180 |
isSameProfile({ 'profile-level-id': '42e01f' }, { 'profile-level-id': '42C02A' }) |
| 181 |
).toBe(true); |
| 182 |
expect( |
| 183 |
isSameProfile({ 'profile-level-id': '42a01f' }, { 'profile-level-id': '58A01F' }) |
| 184 |
).toBe(true); |
| 185 |
expect( |
| 186 |
isSameProfile({ 'profile-level-id': '42e01f' }, undefined) |
| 187 |
).toBe(true); |
| 188 |
}); |
| 189 |
|
| 190 |
test('TestIsNotSameProfile', () => |
| 191 |
{ |
| 192 |
expect( |
| 193 |
isSameProfile(undefined, { 'profile-level-id': '4d001f' }) |
| 194 |
).toBe(false); |
| 195 |
expect( |
| 196 |
isSameProfile({ 'profile-level-id': '42a01f' }, { 'profile-level-id': '640c1f' }) |
| 197 |
).toBe(false); |
| 198 |
expect( |
| 199 |
isSameProfile({ 'profile-level-id': '42000a' }, { 'profile-level-id': '64002a' }) |
| 200 |
).toBe(false); |
| 201 |
}); |
| 202 |
|
| 203 |
test('TestGenerateProfileLevelIdForAnswerEmpty', () => |
| 204 |
{ |
| 205 |
expect(generateProfileLevelIdForAnswer(undefined, undefined)).toBeNull(); |
| 206 |
}); |
| 207 |
|
| 208 |
test('TestGenerateProfileLevelIdForAnswerLevelSymmetryCapped', () => |
| 209 |
{ |
| 210 |
const low_level = |
| 211 |
{ |
| 212 |
'profile-level-id' : '42e015' |
| 213 |
}; |
| 214 |
|
| 215 |
const high_level = |
| 216 |
{ |
| 217 |
'profile-level-id' : '42e01f' |
| 218 |
}; |
| 219 |
|
| 220 |
expect(generateProfileLevelIdForAnswer(low_level, high_level)).toBe('42e015'); |
| 221 |
expect(generateProfileLevelIdForAnswer(high_level, low_level)).toBe('42e015'); |
| 222 |
}); |
| 223 |
|
| 224 |
test('TestGenerateProfileLevelIdForAnswerConstrainedBaselineLevelAsymmetry', () => |
| 225 |
{ |
| 226 |
const local_params = |
| 227 |
{ |
| 228 |
'profile-level-id' : '42e01f', |
| 229 |
'level-asymmetry-allowed' : '1' |
| 230 |
}; |
| 231 |
|
| 232 |
const remote_params = |
| 233 |
{ |
| 234 |
'profile-level-id' : '42e015', |
| 235 |
'level-asymmetry-allowed' : '1' |
| 236 |
}; |
| 237 |
|
| 238 |
expect(generateProfileLevelIdForAnswer(local_params, remote_params)).toBe('42e01f'); |
| 239 |
}); |