more useful app tests

master
Gordon Williams 2023-01-12 11:50:06 +00:00
parent 8bfbffffe5
commit d2154bbfec
1 changed files with 48 additions and 11 deletions

View File

@ -20,17 +20,31 @@ TODO:
*/ */
// A si // A simpletest
var TEST = { /*var TEST = {
app : "android", app : "android",
tests : [ { tests : [ {
load : "messagesgui.app.js",
steps : [ steps : [
{t:"load", fn:"messagesgui.app.js"},
{t:"gb", "obj":{"t":"notify","id":1234,"src":"Twitter","title":"A Name","body":"message contents"}}, {t:"gb", "obj":{"t":"notify","id":1234,"src":"Twitter","title":"A Name","body":"message contents"}},
{t:"cmd", "js":"X='hello';"}, {t:"cmd", "js":"X='hello';"},
{t:"eval", "js":"X", eq:"hello"} {t:"eval", "js":"X", eq:"hello"}
] ]
}] }]
};*/
var TEST = {
app : "antonclk",
tests : [ {
steps : [
{t:"cmd", "js": "Bangle.loadWidgets()"},
{t:"cmd", "js": "eval(require('Storage').read('antonclk.app.js'))"},
{t:"cmd", "js":"Bangle.setUI()"}, // load and free
{t:"saveMemoryUsage"},
{t:"cmd", "js": "eval(require('Storage').read('antonclk.app.js'))"},
{t:"cmd", "js":"Bangle.setUI()"}, // load and free
{t:"checkMemoryUsage"}, // check memory usage is the same
]
}]
}; };
var EMULATOR = "banglejs2"; var EMULATOR = "banglejs2";
@ -73,34 +87,57 @@ function runTest(test) {
console.log(`"${test.app}" Test ${subtestIdx}`); console.log(`"${test.app}" Test ${subtestIdx}`);
console.log(`==============================`); console.log(`==============================`);
emu.factoryReset(); emu.factoryReset();
console.log("Sending app "+test.app); console.log("> Sending app "+test.app);
emu.tx(command); emu.tx(command);
console.log("Sent app"); console.log("> Sent app");
emu.tx(test.load ? `load(${JSON.stringify(test.load)})\n` : "load()\n"); emu.tx("reset()\n");
console.log("App Loaded."); console.log("> Reset.");
var ok = true; var ok = true;
subtest.steps.forEach(step => { subtest.steps.forEach(step => {
if (ok) switch(step.t) { if (ok) switch(step.t) {
case "cmd" : emu.tx(`${step.js}\n`); break; case "load" :
console.log(`> Loading file "${step.fn}"`);
emu.tx(`load(${JSON.stringify(step.fn)})\n`);
break;
case "cmd" :
console.log(`> Sending JS "${step.js}"`);
emu.tx(`${step.js}\n`);
break;
case "gb" : emu.tx(`GB(${JSON.stringify(step.obj)})\n`); break; case "gb" : emu.tx(`GB(${JSON.stringify(step.obj)})\n`); break;
case "tap" : emu.tx(`Bangle.emit(...)\n`); break; case "tap" : emu.tx(`Bangle.emit(...)\n`); break;
case "eval" : case "eval" :
console.log(`> Evaluate "${step.js}"`);
emu.tx(`\x10print(JSON.stringify(${step.js}))\n`); emu.tx(`\x10print(JSON.stringify(${step.js}))\n`);
var result = emu.getLastLine(); var result = emu.getLastLine();
var expected = JSON.stringify(step.eq); var expected = JSON.stringify(step.eq);
console.log("GOT "+result); console.log("> GOT "+result);
if (result!=expected) { if (result!=expected) {
console.log("EXPECTED "+expected); console.log("> FAIL: EXPECTED "+expected);
ok = false; ok = false;
} }
break; break;
// tap/touch/drag/button press // tap/touch/drag/button press
// delay X milliseconds? // delay X milliseconds?
case "screenshot" : case "screenshot" :
console.log("Compare screenshots"); console.log(`> Compare screenshots - UNIMPLEMENTED`);
break;
case "saveMemoryUsage" :
emu.tx(`\x10print(process.memory().usage)\n`);
subtest.memUsage = parseInt( emu.getLastLine());
console.log("> CURRENT MEMORY USAGE", subtest.memUsage);
break;
case "checkMemoryUsage" :
emu.tx(`\x10print(process.memory().usage)\n`);
var memUsage = emu.getLastLine();
console.log("> CURRENT MEMORY USAGE", memUsage);
if (subtest.memUsage != memUsage ) {
console.log("> FAIL: EXPECTED MEMORY USAGE OF "+subtest.memUsage);
ok = false;
}
break; break;
default: ERROR("Unknown step type "+step.t); default: ERROR("Unknown step type "+step.t);
} }
emu.idle();
}); });
}); });
emu.stopIdle(); emu.stopIdle();