Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
dbushell committed Sep 25, 2022
1 parent fbfb31e commit 7d46ecf
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ Building from source on a Raspberry Pi installs at:

On Windows see [HIDAPI Releases](https://github.com/libusb/hidapi/releases/) (I've not tested Windows).

## Testing

There is a basic Deno test to check the HIDAPI library defined by the `DENO_USBHIDAPI` environment variable.

```sh
deno test --unstable --allow-all src/test.ts
```

## Resources

* [libusb/hidapi](https://github.com/libusb/hidapi/) — HIDAPI library for Windows, Linux, FreeBSD and macOS.
Expand Down
33 changes: 33 additions & 0 deletions src/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import {
assertEquals,
assertRejects
} from 'https://deno.land/std@0.157.0/testing/asserts.ts';
import {hidapi} from './hidapi.ts';
import * as utils from './utils.ts';

Deno.test('HIDAPI missing', () => {
assertRejects(
() =>
new Promise((resolve, reject) => {
Deno.env.set('DENO_USBHIDAPI', './missing');
import('./hidapi.ts?nocache').then(resolve).catch(reject);
})
);
});

Deno.test('HIDAPI version number', () => {
const buffer = Deno.UnsafePointerView.getArrayBuffer(
hidapi.symbols.hid_version(),
24
);
const view = new DataView(buffer);
assertEquals(view.getUint8(4), 12);
});

Deno.test('HIDAPI version string ("0.12.0")', () => {
const buffer = Deno.UnsafePointerView.getArrayBuffer(
hidapi.symbols.hid_version_str(),
32
);
assertEquals(utils.decodeUTF8(buffer), '0.12.0');
});

0 comments on commit 7d46ecf

Please sign in to comment.