Skip to content

Commit 5e312b3

Browse files
authored
Merge pull request #3399 from halemmerich/gpstests
Implements more asserts and reading testcases from json files
2 parents 04bc4dd + b1e7c1b commit 5e312b3

File tree

4 files changed

+507
-90
lines changed

4 files changed

+507
-90
lines changed

apps/android/test.json

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"app" : "android",
3+
"setup" : [{
4+
"id": "default",
5+
"steps" : [
6+
{"t":"cmd", "js": "Bangle.setGPSPower=(isOn, appID)=>{if (!appID) appID='?';if (!Bangle._PWR) Bangle._PWR={};if (!Bangle._PWR.GPS) Bangle._PWR.GPS=[];if (isOn && !Bangle._PWR.GPS.includes(appID)) Bangle._PWR.GPS.push(appID);if (!isOn && Bangle._PWR.GPS.includes(appID)) Bangle._PWR.GPS.splice(Bangle._PWR.GPS.indexOf(appID),1);return Bangle._PWR.GPS.length>0;};", "text": "Fake the setGPSPower"},
7+
{"t":"wrap", "fn": "Bangle.setGPSPower", "id": "gpspower"},
8+
{"t":"cmd", "js": "NRF.getSecurityStatus = () => { return { connected: false };}", "text": "Control the security status"},
9+
{"t":"cmd", "js": "Serial1.println = () => { }", "text": "Fake the serial port println"},
10+
{"t":"cmd", "js": "Bluetooth.println = () => { }", "text": "Fake the Bluetooth println"},
11+
{"t":"cmd", "js": "Bangle._PWR={}", "text": "Prepare an empty _PWR for following asserts"},
12+
{"t":"cmd", "js": "require('Storage').writeJSON('android.settings.json', {overwriteGps: true})", "text": "Enable GPS overwrite"},
13+
{"t":"cmd", "js": "eval(require('Storage').read('android.boot.js'))", "text": "Load the boot code"}
14+
]
15+
}],
16+
"tests" : [{
17+
"description": "Check setGPSPower is replaced",
18+
"steps" : [
19+
{"t":"cmd", "js": "Serial1.println = () => { }", "text": "Fake the serial port"},
20+
{"t":"cmd", "js": "Bluetooth.println = () => { }", "text": "Fake the Bluetooth println"},
21+
{"t":"cmd", "js": "require('Storage').writeJSON('android.settings.json', {overwriteGps: true})", "text": "Enable GPS overwrite"},
22+
{"t":"cmd", "js": "eval(require('Storage').read('android.boot.js'))", "text": "Load the boot code"},
23+
{"t":"assert", "js": "Bangle.setGPSPower.toString().includes('native')", "is":"false", "text": "setGPSPower has been replaced"}
24+
]
25+
},{
26+
"description": "Test switching hardware GPS on and off",
27+
"steps" : [
28+
{"t":"setup", "id": "default"},
29+
{"t":"assertArray", "js": "Bangle._PWR.GPS", "is":"undefinedOrEmpty", "text": "No GPS clients"},
30+
{"t":"assert", "js": "Bangle.isGPSOn()", "is":"falsy", "text": "isGPSOn shows GPS as off"},
31+
{"t":"assert", "js": "Bangle.setGPSPower(1, 'test')", "is":"truthy", "text": "setGPSPower returns truthy when switching on"},
32+
{"t":"assertArray", "js": "Bangle._PWR.GPS", "is":"notEmpty", "text": "GPS clients"},
33+
{"t":"assert", "js": "Bangle.isGPSOn()", "is":"truthy", "text": "isGPSOn shows GPS as on"},
34+
{"t":"assertCall", "id": "gpspower", "count": 1, "argAsserts": [ { "t": "assert", "arg": "0", "is": "equal", "to": 1 } ] , "text": "internal GPS switched on"},
35+
{"t":"assert", "js": "Bangle.setGPSPower(0, 'test')", "is":"falsy", "text": "setGPSPower returns falsy when switching off"},
36+
{"t":"assertArray", "js": "Bangle._PWR.GPS", "is":"undefinedOrEmpty", "text": "No GPS clients"},
37+
{"t":"assert", "js": "Bangle.isGPSOn()", "is":"falsy", "text": "isGPSOn shows GPS as off"},
38+
{"t":"assertCall", "id": "gpspower", "count": 2, "argAsserts": [ { "t": "assert", "arg": "0", "is": "equal", "to": 0 } ] , "text": "internal GPS switched off"}
39+
]
40+
}]
41+
}

apps/antonclk/test.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"app" : "antonclk",
3+
"tests" : [{
4+
"description": "Check memory usage after setUI",
5+
"steps" : [
6+
{"t":"cmd", "js": "Bangle.loadWidgets()"},
7+
{"t":"cmd", "js": "eval(require('Storage').read('antonclk.app.js'))"},
8+
{"t":"cmd", "js": "Bangle.setUI()"},
9+
{"t":"saveMemoryUsage"},
10+
{"t":"cmd", "js": "eval(require('Storage').read('antonclk.app.js'))"},
11+
{"t":"cmd", "js":"Bangle.setUI()"},
12+
{"t":"checkMemoryUsage"}
13+
]
14+
}]
15+
}

apps/messagesoverlay/test.json

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"app" : "messagesoverlay",
3+
"tests" : [{
4+
"description": "Test handler backgrounding",
5+
"steps" : [
6+
{"t":"upload", "file": "modules/widget_utils.js", "as": "widget_utils"},
7+
{"t":"cmd", "js": "Bangle.loadWidgets()", "text": "Load widgets"},
8+
{"t":"assertArray", "js": "Bangle['#onswipe']", "is":"undefinedOrEmpty", "text": "No swipe handlers"},
9+
{"t":"cmd", "js": "require('widget_utils').swipeOn(0)", "text": "Store widgets in overlay"},
10+
{"t":"assert", "js": "Bangle['#onswipe']", "is":"function", "text": "One swipe handler for widgets"},
11+
{"t":"emit", "event":"swipe", "paramsArray": [ 0, 1 ], "text": "Show widgets"},
12+
{"t":"assert", "js": "Bangle['#onswipe']", "is":"function", "text": "One swipe handler for widgets"},
13+
{"t":"cmd", "js": "require('messagesoverlay').message('text', {src:'Messenger',t:'add',type:'text',id:Date.now().toFixed(0),title:'title',body:'body'})", "text": "Show a message overlay"},
14+
{"t":"assertArray", "js": "Bangle['#onswipe']", "is":"undefinedOrEmpty", "text": "No swipe handlers while message overlay is on screen"},
15+
{"t":"emit", "event":"touch", "paramsArray": [ 1, { "x": 10, "y": 10, "type": 0 } ], "text": "Close message"},
16+
{"t":"assert", "js": "Bangle['#onswipe']", "is":"function", "text": "One swipe handler restored"}
17+
]
18+
},{
19+
"description": "Test handler backgrounding with fastloading (setUI)",
20+
"steps" : [
21+
{"t":"cmd", "js": "Bangle.on('swipe',print)", "text": "Create listener for swipes"},
22+
{"t":"cmd", "js": "Bangle.setUI({mode: 'clock',remove: ()=>{}})", "text": "Init UI for clock"},
23+
{"t":"cmd", "js": "require('messagesoverlay').message('text', {src:'Messenger',t:'add',type:'text',id:Date.now().toFixed(0),title:'title',body:'body'})", "text": "Show a message overlay"},
24+
{"t":"assertArray", "js": "Bangle['#onswipe']", "is":"undefinedOrEmpty", "text": "No swipe handlers while message overlay is on screen"},
25+
{"t":"cmd", "js": "Bangle.setUI()", "text": "Trigger removal of UI"},
26+
{"t":"assertArray", "js": "Bangle['#onswipe']", "is":"undefinedOrEmpty", "text": "Still no swipe handlers"},
27+
{"t":"cmd", "js": "Bangle.on('touch', print)"},
28+
{"t":"emit", "event":"touch", "paramsArray": [ 1, { "x": 10, "y": 10, "type": 0 } ], "text": "Close message"},
29+
{"t":"assert", "js": "Bangle['#onswipe']", "is":"function", "text": "One swipe handler restored"}
30+
]
31+
}]
32+
}

0 commit comments

Comments
 (0)