Skip to content

Commit

Permalink
add integration tests
Browse files Browse the repository at this point in the history
update emu readme
work around issue #163
  • Loading branch information
neophob committed Nov 18, 2019
1 parent dad509a commit 6766c71
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 131 deletions.
116 changes: 1 addition & 115 deletions lib/emu/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Visual PinMAME Control

### STATS:
### STATS

A quick evaluation of 357 VPX VBS files, showed this amount of API Calls

Expand Down Expand Up @@ -49,43 +49,6 @@ A quick evaluation of 357 VPX VBS files, showed this amount of API Calls
- .B2SSetData 505
- .GetMech 38

### STATE
Should be implemented - BASIC

#### PoC

```
const Control = {
gameName: '',
running: false,
pause: false,
get GameName() {
return this.gameName;
},
set GameName(gameName) {
this.gameName = gameName;
},
get Running() {
return this.running;
},
get Pause() {
return this.pause;
},
set Pause(pause) {
this.pause = pause;
},
get Version() {
return '1.10.11';
},
Run() {
console.log('BOO HOO');
},
Stop() {
console.log('STOP');
}
}
```

### Properties

- GameName, Read/Write: Initializes VPinMAME for game "gameName". Example Controller.GameName = "tz_94h"
Expand All @@ -102,28 +65,6 @@ minVersion: Minimum version of Visual PinMAME (e.g. 100 for 1.00) required to ru

## Game Settings

### STATE
Should be implemented.

#### PoC

```
const GameSetting = {
get Dip() {
//TODO unclear
},
set Dip(dipBankNumber) {
//TODO unclear
},
get WPCNumbering() {
return this.pause;
},
get SampleRate() {
return 22050;
},
}
```

### Properties

- Dip (Dip Bank Number), Read/Write, Sets/Gets the Dip switch settings for the current game. Dip Bank Number: dip 1-8 = bank 0, dip 9-16 = bank 1 ... value: binary value to set the dips 1=On, 0=Off. Example: Controller.Dip(0) = &H55, Controller.Dip(1) = &Haa
Expand All @@ -133,9 +74,6 @@ const GameSetting = {

## Customization

### STATE
Will skip implementation unless we need.

### Properties

- SplashInfoLine, Read/Write, Game credits to display in startup splash screen. Example: Controller.SplashInfoLine = "Game design by ..."
Expand Down Expand Up @@ -169,36 +107,12 @@ Controller.CheckROMS(0,hWnd) : Displays the results of the ROM check (hWnd = Han

## Aggregate Polling Functions


These properties return a matrix with everything that has changed since the last call.
The array contains the following info
Matrix(0,0) Number of first changed item
Matrix(0,1) New status of first item
Matrix(1,0) Number of second changed item

### STATE
Should be implemented - BASIC

#### PoC

```
const AggregatePollingFunctions = {
get ChangedLamps() {
return x;
},
get ChangedSolenoids() {
return x;
},
get ChangedGI() {
return x;
},
get ChangedLEDs() {
return '1.10.11';
},
}
```


### Properties

- ChangedLamps, Read Only, Returns which lamps have changed since last call to this property!
Expand All @@ -208,28 +122,6 @@ const AggregatePollingFunctions = {

## Game Input/Output

### STATE
Should be implemented - BASIC

#### PoC

```
const GameInputOutput = {
get Lamp(number) {
return x;
},
get Solenoid(number) {
return x;
},
get GIString(number) {
return x;
},
get Switch(number) {
return x;
},
}
```

### Properties

- Lamp(number), Read Only, Get status of a single lamp, return: True = Lamp on, False = Lamp off
Expand All @@ -239,9 +131,6 @@ const GameInputOutput = {

## Debugging

### STATE
Will skip implementation unless we need.

### Properties

- ShowDMDOnly, Read/Write, Enable/disable VPinMAME status matrices.
Expand All @@ -250,9 +139,6 @@ Will skip implementation unless we need.

## Events

### STATE
Will skip implementation unless we need.

May not be supported in all scripting environments!

- OnSolenoid(solenoidNo, isActive), Called whenever a solenoid changes state
Expand Down
27 changes: 11 additions & 16 deletions lib/scripting/objects/vbs-to-wpcemu.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { Emulator } from '../../emu/wpc-emu';

/* tslint:disable:no-unused-expression no-string-literal */
chai.use(require('sinon-chai'));
describe.only('VpmController integration test', () => {
describe('VpmController integration test', () => {

const sandbox = sinon.createSandbox();
let setSwitchInputSpy: SinonStub<[number, boolean?]>;
Expand All @@ -46,52 +46,47 @@ describe.only('VpmController integration test', () => {
sandbox.restore();
});

it('VBS should update switch, Controller.Switch()', () => {
function setupPlayerTable(vbs) {
const scope = {};
const vbs = `Dim Controller\nSet Controller = CreateObject("VPinMAME.Controller")\nController.Switch(49) = 0\nController.Switch(51) = 1`;
const table = new TableBuilder().withTableScript(vbs).build('Table1');
new Player(table).init(scope);
}

it('VBS should update switch, Controller.Switch()', () => {
const vbs = `Dim Controller\nSet Controller = CreateObject("VPinMAME.Controller")\nController.Switch(49) = 0\nController.Switch(51) = 1`;
setupPlayerTable(vbs);
expect(setSwitchInputSpy.args.length).to.equal(2);
expect(setSwitchInputSpy.args[0]).to.deep.equal([ 49, false ]);
expect(setSwitchInputSpy.args[1]).to.deep.equal([ 51, true ]);
});

it.skip('VBS should update language setting, Controller.DIP()', () => {
const scope = {};
it('VBS should update language setting, Controller.DIP()', () => {
const vbs = `Dim Controller\nSet Controller = CreateObject("VPinMAME.Controller")\nController.DIP(0) = &H00`;
const table = new TableBuilder().withTableScript(vbs).build('Table1');
new Player(table).init(scope);
setupPlayerTable(vbs);

expect(setDipSwitchByteSpy.args.length).to.equal(1);
expect(setDipSwitchByteSpy.args[0]).to.deep.equal([ 0 ]);
});

it('VBS should update language setting, Controller.Dip()', () => {
const scope = {};
const vbs = `Dim Controller\nSet Controller = CreateObject("VPinMAME.Controller")\nController.Dip(0) = &H70`;
const table = new TableBuilder().withTableScript(vbs).build('Table1');
new Player(table).init(scope);
setupPlayerTable(vbs);

expect(setDipSwitchByteSpy.args.length).to.equal(1);
expect(setDipSwitchByteSpy.args[0]).to.deep.equal([ 112 ]);
});

it('VBS should read solenoid, Controller.Solenoid()', () => {
const scope = {};
const vbs = `Dim Controller\nSet Controller = CreateObject("VPinMAME.Controller")\nController.Solenoid(4)`;
const table = new TableBuilder().withTableScript(vbs).build('Table1');
new Player(table).init(scope);
setupPlayerTable(vbs);

expect(getSolenoidSpy.args.length).to.equal(1);
expect(getSolenoidSpy.args[0]).to.deep.equal([ 4 ]);
});

it('VBS should read lamp, Controller.Lamp()', () => {
const scope = {};
const vbs = `Dim Controller\nSet Controller = CreateObject("VPinMAME.Controller")\nController.Lamp(3)`;
const table = new TableBuilder().withTableScript(vbs).build('Table1');
new Player(table).init(scope);
setupPlayerTable(vbs);

expect(getLampSpy.args.length).to.equal(1);
expect(getLampSpy.args[0]).to.deep.equal([ 3 ]);
Expand Down
4 changes: 4 additions & 0 deletions lib/scripting/objects/vpm-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export class VpmController {
private splashInfoLine: string = '';
private readonly player: Player;
public readonly Dip: { [index: number]: number };
public readonly DIP: { [index: number]: number };
public readonly Switch: { [index: number]: number };
public readonly Lamp: { [index: number]: number };
public readonly Solenoid: { [index: number]: number };
Expand Down Expand Up @@ -75,6 +76,9 @@ export class VpmController {
return true;
},
);
// See https://github.com/vpdb/vpx-js/issues/163
this.DIP = this.Dip;

this.Lamp = this.createGetSetNumberProxy('LAMP',
(index) => this.emulator.getLampState(index), SET_NOP);
this.Solenoid = this.createGetSetNumberProxy('SOLENOID',
Expand Down

0 comments on commit 6766c71

Please sign in to comment.