-
Notifications
You must be signed in to change notification settings - Fork 113
Expand file tree
/
Copy pathtest_osn_audio.ts
More file actions
94 lines (81 loc) · 3.8 KB
/
Copy pathtest_osn_audio.ts
File metadata and controls
94 lines (81 loc) · 3.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import 'mocha';
import { expect } from 'chai';
import * as osn from '../osn';
import { logInfo, logEmptyLine } from '../util/logger';
import { OBSHandler } from '../util/obs_handler';
import { deleteConfigFiles } from '../util/general';
import { ETestErrorMsg, GetErrorMessage } from '../util/error_messages';
const testName = 'osn-audio';
describe(testName, () => {
let obs: OBSHandler;
let hasTestFailed: boolean = false;
// Initialize OBS process
before(function() {
logInfo(testName, 'Starting ' + testName + ' tests');
deleteConfigFiles();
obs = new OBSHandler(testName);
});
// Shutdown OBS process
after(async function() {
obs.shutdown();
if (hasTestFailed === true) {
logInfo(testName, 'One or more test cases failed. Uploading cache');
await obs.uploadTestCache();
}
obs = null;
deleteConfigFiles();
logInfo(testName, 'Finished ' + testName + ' tests');
logEmptyLine();
});
afterEach(function() {
if (this.currentTest.state == 'failed') {
hasTestFailed = true;
}
});
it('Get and set audio context', () => {
let currentAudio = osn.AudioFactory.audioContext;
// Check if the current video context correctly returns the default values
expect(currentAudio.sampleRate).to.equal(44100, GetErrorMessage(ETestErrorMsg.AudioDefaultSampleRate));
expect(currentAudio.speakers).to.equal(osn.ESpeakerLayout.Stereo, GetErrorMessage(ETestErrorMsg.AudioDefaultSpeakers));
const newAudioContext: osn.IAudio = {
sampleRate: 48000,
speakers: osn.ESpeakerLayout.SevenOne
}
osn.AudioFactory.audioContext = newAudioContext;
currentAudio = osn.AudioFactory.audioContext;
expect(currentAudio.sampleRate).to.equal(48000, GetErrorMessage(ETestErrorMsg.AudioSampleRate));
expect(currentAudio.speakers).to.equal(osn.ESpeakerLayout.SevenOne, GetErrorMessage(ETestErrorMsg.AudioSpeakers));
});
it('Get output audio devices', function() {
const devices = osn.NodeObs.OBS_settings_getOutputAudioDevices();
expect(devices).to.not.equal(undefined, GetErrorMessage(ETestErrorMsg.AudioDevices));
expect(Array.isArray(devices)).to.equal(true, GetErrorMessage(ETestErrorMsg.AudioDevicesIsArray));
let foundDefaultDevice = false;
for (const device of devices) {
expect(device).to.have.property('id');
expect(device).to.have.property('description');
logInfo(testName, `Output Audio Device Found: ${device.description} with id: ${device.id}`);
if (device.id === 'default') {
foundDefaultDevice = true;
}
}
if (!obs.isDarwinCI()) { // On virtual mac(s) the default output device is not included in the list of output devices
expect(foundDefaultDevice).to.equal(true, GetErrorMessage(ETestErrorMsg.DefaultDeviceNotFound));
}
});
it('Get input audio devices', function() {
const devices = osn.NodeObs.OBS_settings_getInputAudioDevices();
expect(devices).to.not.equal(undefined, GetErrorMessage(ETestErrorMsg.AudioDevices));
expect(Array.isArray(devices)).to.equal(true, GetErrorMessage(ETestErrorMsg.AudioDevicesIsArray));
let foundDefaultDevice = false;
for (const device of devices) {
expect(device).to.have.property('id');
expect(device).to.have.property('description');
logInfo(testName, `Input Audio Device Found: ${device.description} with id: ${device.id}`);
if (device.id === 'default') {
foundDefaultDevice = true;
}
}
expect(foundDefaultDevice).to.equal(true, GetErrorMessage(ETestErrorMsg.DefaultDeviceNotFound));
});
});