Skip to content

Commit a2be96d

Browse files
committed
Update unit and manager tests
1 parent 03da212 commit a2be96d

8 files changed

Lines changed: 41 additions & 94 deletions

File tree

tests/managers/AppClient.js

Lines changed: 14 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,18 @@ const SDL = require('../../lib/node/dist/SDL.min.js');
3434
const CONFIG = require('./config.js');
3535

3636
class AppClient {
37-
constructor (wsClient) {
37+
constructor (wsClient, ready) {
3838
const fileName = `${CONFIG.appId}_icon.gif`;
3939
const file = new SDL.manager.file.filetypes.SdlFile()
4040
.setName(fileName)
4141
.setFilePath('./test_icon_1.png')
4242
.setType(SDL.rpc.enums.FileType.GRAPHIC_PNG)
4343
.setPersistent(true);
4444

45-
this._appConfig = new SDL.manager.AppConfig()
45+
this._lifecycleConfig = new SDL.manager.LifecycleConfig()
4646
.setAppId(CONFIG.appId)
4747
.setAppName(CONFIG.appName)
48-
.setIsMediaApp(false)
4948
.setLanguageDesired(SDL.rpc.enums.Language.EN_US)
50-
.setHmiDisplayLanguageDesired(SDL.rpc.enums.Language.EN_US)
5149
.setAppTypes([
5250
SDL.rpc.enums.AppHMIType.DEFAULT,
5351
])
@@ -59,6 +57,9 @@ class AppClient {
5957
)
6058
.setAppIcon(file);
6159

60+
this._appConfig = new SDL.manager.AppConfig()
61+
.setLifecycleConfig(this._lifecycleConfig);
62+
6263
const managerListener = new SDL.manager.SdlManagerListener();
6364
managerListener
6465
.setOnStart((sdlManager) => {
@@ -72,86 +73,26 @@ class AppClient {
7273
this._sdlManager
7374
.start()
7475
.addRpcListener(SDL.rpc.enums.FunctionID.OnHMIStatus, this._onHmiStatusListener.bind(this));
75-
this._sdlManager.initialize();
76+
77+
this._ready = ready;
7678
}
7779

7880
async _onConnected () {
79-
// add voice commands for when the managers are ready
80-
const screenManager = this._sdlManager.getScreenManager();
81-
screenManager.setVoiceCommands([
82-
new SDL.manager.screen.utils.VoiceCommand(['Option 1'], () => {
83-
console.log('Option one selected!');
84-
}),
85-
new SDL.manager.screen.utils.VoiceCommand(['Option 2'], () => {
86-
console.log('Option two selected!');
87-
}),
88-
new SDL.manager.screen.utils.VoiceCommand(['Option 3'], () => {
89-
console.log('Option three selected!');
90-
}),
91-
]);
92-
93-
// set up the presentation for the manager when its ready
94-
screenManager.setTextField1('Hello SDL!');
95-
screenManager.setTextField2('こんにちは');
96-
screenManager.setTextField3('你好');
97-
screenManager.setTitle('JavaScript Library');
98-
screenManager.setTextAlignment(SDL.rpc.enums.TextAlignment.RIGHT_ALIGNED);
99-
screenManager.setPrimaryGraphic(new SDL.manager.file.filetypes.SdlArtwork('sdl-logo', SDL.rpc.enums.FileType.GRAPHIC_PNG)
100-
.setFilePath('./test_icon_1.png'));
81+
10182
}
10283

10384
async _onHmiStatusListener (onHmiStatus) {
10485
const hmiLevel = onHmiStatus.getHmiLevel();
10586

10687
// wait for the FULL state for more functionality
10788
if (hmiLevel === SDL.rpc.enums.HMILevel.HMI_FULL) {
108-
const art1 = new SDL.manager.file.filetypes.SdlArtwork('logo', SDL.rpc.enums.FileType.GRAPHIC_PNG)
109-
.setFilePath('./test_icon_1.png');
110-
111-
const state1 = new SDL.manager.screen.utils.SoftButtonState('ROCK', 'rock', art1);
112-
const state2 = new SDL.manager.screen.utils.SoftButtonState('PAPER', 'paper', art1);
113-
const state3 = new SDL.manager.screen.utils.SoftButtonState('SCISSORS', 'scissors', art1);
114-
const state4 = new SDL.manager.screen.utils.SoftButtonState('BUTTON', 'button');
115-
116-
const softButtonObjects = [
117-
new SDL.manager.screen.utils.SoftButtonObject('game', [state1, state2, state3], 'ROCK', (id, rpc) => {
118-
if (rpc instanceof SDL.rpc.messages.OnButtonPress) {
119-
console.log('First button pressed!');
120-
}
121-
}),
122-
new SDL.manager.screen.utils.SoftButtonObject('button', [state4], 'BUTTON', (id, rpc) => {
123-
if (rpc instanceof SDL.rpc.messages.OnButtonPress) {
124-
console.log('Second button pressed!');
125-
}
126-
}),
127-
];
128-
129-
// set the softbuttons now and rotate through the states of the first softbutton
130-
const screenManager = this._sdlManager.getScreenManager();
131-
await screenManager.setSoftButtonObjects(softButtonObjects);
132-
133-
await this._sleep(2000);
134-
softButtonObjects[0].transitionToNextState();
135-
await this._sleep(2000);
136-
softButtonObjects[0].transitionToNextState();
137-
await this._sleep(2000);
138-
139-
const count = 3;
140-
for (let secondsLeft = 0; secondsLeft < count; secondsLeft++) {
141-
const showCountdown = new SDL.rpc.messages.Show();
142-
showCountdown.setMainField1(`Exiting in ${(count - secondsLeft).toString()}`)
143-
.setMainField2('')
144-
.setMainField3('');
145-
146-
this._sdlManager.sendRpc(showCountdown); // don't wait for a response
147-
148-
await this._sleep();
89+
if (typeof this._ready === 'function') {
90+
this._ready(async () => {
91+
// tests complete. tear down the app
92+
await this._sdlManager.sendRpc(new SDL.rpc.messages.UnregisterAppInterface());
93+
this._sdlManager.dispose();
94+
});
14995
}
150-
151-
// tear down the app
152-
await this._sdlManager.sendRpc(new SDL.rpc.messages.UnregisterAppInterface());
153-
154-
this._sdlManager.dispose();
15596
}
15697
}
15798

tests/managers/index.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,18 @@ describe('ManagerTests', function () {
1111
it('StartManagerTests', function (done) {
1212
const appWebSocketServer = new WS.Server({ port: 3005 });
1313
appWebSocketServer.on('connection', function (connection) {
14-
const appClient = new AppClient(connection);
15-
permissionManagerTests(appClient);
16-
softButtonManagerTests(appClient);
17-
screenManagerTests(appClient);
18-
lifecycleManagerTests(appClient);
19-
done();
14+
const appClient = new AppClient(connection, async (teardown) => {
15+
permissionManagerTests(appClient);
16+
softButtonManagerTests(appClient);
17+
screenManagerTests(appClient);
18+
lifecycleManagerTests(appClient);
19+
setTimeout(function () {
20+
teardown();
21+
done();
22+
}, 2000);
23+
});
24+
25+
2026
});
2127
});
2228
});

tests/managers/lifecycle/LifecycleManagerTests.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ module.exports = function (appClient) {
3434
*/
3535
function validateRpcResponse (response) {
3636
Validator.assertTrue(response.getSuccess());
37-
Validator.assertEquals(response.getFunctionName(), 'ListFiles');
37+
Validator.assertEquals(response.getFunctionId(), 'ListFiles');
3838
}
3939
it('testRpcListener', function (done) {
4040
sdlManager.addRpcListener(SDL.rpc.enums.FunctionID.ListFiles, validateRpcResponse);

tests/managers/screen/ScreenManagerTests.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ module.exports = function (appClient) {
2424
Validator.assertTrue(screenManager.getVoiceCommands().length === 0);
2525
Validator.assertNotNullUndefined(screenManager.getSoftButtonObjects());
2626
Validator.assertNull(screenManager.getSoftButtonObjectByName('test'));
27-
Validator.assertNull(screenManager.getSoftButtonObjectById(1));
27+
Validator.assertNull(screenManager._getSoftButtonObjectById(1));
2828
done();
2929
});
3030

tests/managers/screen/SoftButtonManagerTests.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,17 @@ module.exports = function (appClient) {
2121

2222
it('testSoftButtonManagerUpdate', function (done) {
2323
screenManager.setSoftButtonObjects([softButtonObject]);
24-
softButtonObject.setButtonId(softButtonObjectId);
24+
softButtonObject._setButtonId(softButtonObjectId);
2525
Validator.assertNotNullUndefined(softButtonManager);
2626
Validator.assertEquals([softButtonObject], softButtonManager.getSoftButtonObjects());
2727
done();
2828
});
2929

3030
it('testSoftButtonManagerGetSoftButtonObject', function (done) {
3131
Validator.assertNull(softButtonManager.getSoftButtonObjectByName('INVALID'));
32-
Validator.assertNull(softButtonManager.getSoftButtonObjectById('infinity'));
32+
Validator.assertNull(softButtonManager._getSoftButtonObjectById('infinity'));
3333
Validator.assertEquals(softButtonObject, softButtonManager.getSoftButtonObjectByName('game'));
34-
Validator.assertEquals(softButtonObject, softButtonManager.getSoftButtonObjectById(softButtonObjectId));
34+
Validator.assertEquals(softButtonObject, softButtonManager._getSoftButtonObjectById(softButtonObjectId));
3535
done();
3636
});
3737

@@ -84,19 +84,19 @@ module.exports = function (appClient) {
8484

8585
// sbo1 = new SDL.manager.screen.utils.SoftButtonObject(null, [], null, null);
8686
sbo1 = new SDL.manager.screen.utils.SoftButtonObject(null, [state1, state2, state3], state1.getName(), null);
87-
sbo1.setButtonId(100);
87+
sbo1._setButtonId(100);
8888
// sbo2 = new SDL.manager.screen.utils.SoftButtonObject(null, [], null, null);
8989
sbo2 = new SDL.manager.screen.utils.SoftButtonObject(null, [state1, state2, state3], state1.getName(), null);
90-
sbo2.setButtonId(200);
90+
sbo2._setButtonId(200);
9191
// sbo3 = new SDL.manager.screen.utils.SoftButtonObject(null, [], null, null);
9292
sbo3 = new SDL.manager.screen.utils.SoftButtonObject(null, [state1, state2, state3], state1.getName(), null);
93-
sbo3.setButtonId(300);
93+
sbo3._setButtonId(300);
9494
// sbo4 = new SDL.manager.screen.utils.SoftButtonObject(null, [], null, null);
9595
sbo4 = new SDL.manager.screen.utils.SoftButtonObject(null, [state1, state2, state3], state1.getName(), null);
96-
sbo4.setButtonId(400);
96+
sbo4._setButtonId(400);
9797
// sbo5 = new SDL.manager.screen.utils.SoftButtonObject(null, [], null, null);
9898
sbo5 = new SDL.manager.screen.utils.SoftButtonObject(null, [state1, state2, state3], state1.getName(), null);
99-
sbo5.setButtonId(500);
99+
sbo5._setButtonId(500);
100100
softButtonManager._checkAndAssignButtonIds([sbo1, sbo2, sbo3, sbo4, sbo5]);
101101
Validator.assertEquals(100, sbo1.getButtonId());
102102
Validator.assertEquals(200, sbo2.getButtonId());
@@ -106,14 +106,14 @@ module.exports = function (appClient) {
106106

107107
// sbo1 = new SDL.manager.screen.utils.SoftButtonObject(null, [], null, null);
108108
sbo1 = new SDL.manager.screen.utils.SoftButtonObject(null, [state1, state2, state3], state1.getName(), null);
109-
sbo1.setButtonId(50);
109+
sbo1._setButtonId(50);
110110
// sbo2 = new SDL.manager.screen.utils.SoftButtonObject(null, [], null, null);
111111
sbo2 = new SDL.manager.screen.utils.SoftButtonObject(null, [state1, state2, state3], state1.getName(), null);
112112
// sbo3 = new SDL.manager.screen.utils.SoftButtonObject(null, [], null, null);
113113
sbo3 = new SDL.manager.screen.utils.SoftButtonObject(null, [state1, state2, state3], state1.getName(), null);
114114
// sbo4 = new SDL.manager.screen.utils.SoftButtonObject(null, [], null, null);
115115
sbo4 = new SDL.manager.screen.utils.SoftButtonObject(null, [state1, state2, state3], state1.getName(), null);
116-
sbo4.setButtonId(100);
116+
sbo4._setButtonId(100);
117117
// sbo5 = new SDL.manager.screen.utils.SoftButtonObject(null, [], null, null);
118118
sbo5 = new SDL.manager.screen.utils.SoftButtonObject(null, [state1, state2, state3], state1.getName(), null);
119119
softButtonManager._checkAndAssignButtonIds([sbo1, sbo2, sbo3, sbo4, sbo5]);

tests/node/streaming/video/VideoStreamingParametersTest.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const VideoStreamingCapability = SDL.rpc.structs.VideoStreamingCapability;
77
const VideoStreamingFormat = SDL.rpc.structs.VideoStreamingFormat;
88
const VideoStreamingCodec = SDL.rpc.enums.VideoStreamingCodec;
99
const VideoStreamingProtocol = SDL.rpc.enums.VideoStreamingProtocol;
10-
const VideoStreamingParameters = SDL.streaming.video.VideoStreamingParameters;
10+
const VideoStreamingParameters = SDL.streaming.video._VideoStreamingParameters;
1111

1212
const params = new VideoStreamingParameters();
1313
const capability = new VideoStreamingCapability();

tests/node/util/BitConverterTest.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
const SDL = require('./../../../lib/js/dist/SDL.min.js');
3-
const BitConverter = SDL.util.BitConverter;
3+
const BitConverter = SDL.util._BitConverter;
44
const Validator = require('./../../Validator.js');
55

66
describe('BitConverterTest', function () {

tests/node/util/BsonTest.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const SDL = require('./../../../lib/js/dist/SDL.min.js');
2-
const Bson = SDL.util.Bson;
2+
const Bson = SDL.util._Bson;
33
const Validator = require('./../../Validator.js');
44

55
const testBuffer = new Uint8Array([12, 0, 0, 0, 16, 120, 0, 1, 0, 0, 0, 0]);

0 commit comments

Comments
 (0)