Add Dpt11 tests.
This commit is contained in:
@@ -9,5 +9,56 @@ import { compareBuffers } from "./util"
|
||||
describe("Test DPT011", (): void => {
|
||||
|
||||
let dpt = new DPT11();
|
||||
let value = new Date(2021, 11, 25)
|
||||
let buffer = Buffer.from([25, 12, 21])
|
||||
|
||||
it("Decode buffer acceptable", async function () {
|
||||
const decoded = dpt.decoder(buffer)
|
||||
expect(decoded.toUTCString()).is.equal(value.toUTCString());
|
||||
});
|
||||
|
||||
it("Decode empty buffer", async function () {
|
||||
let bufferEmpty = Buffer.from([])
|
||||
var testFunction = function () {
|
||||
const value = dpt.decoder(bufferEmpty)
|
||||
}
|
||||
expect(testFunction).to.throw(BufferLengthError);
|
||||
});
|
||||
|
||||
it("Decode invalid buffer", async function () {
|
||||
let bufferEmpty = Buffer.from([25, 13, 21])
|
||||
var testFunction = function () {
|
||||
const value = dpt.decoder(bufferEmpty)
|
||||
}
|
||||
expect(testFunction).to.throw(InvalidValueError);
|
||||
});
|
||||
|
||||
it("Decode oversized buffer", async function () {
|
||||
let bufferBiggerSize = Buffer.from([0x20, 0x15, 0, 0])
|
||||
|
||||
var testFunction = function () {
|
||||
const value = dpt.decoder(bufferBiggerSize)
|
||||
}
|
||||
expect(testFunction).to.throw(BufferLengthError);
|
||||
});
|
||||
|
||||
/* Encoder tests */
|
||||
it("encode valid", async function () {
|
||||
expect(compareBuffers(dpt.encoder(value), buffer)).is.true;
|
||||
});
|
||||
|
||||
it("encode undefined", async function () {
|
||||
var testFunction = function () {
|
||||
const value = dpt.encoder(undefined)
|
||||
}
|
||||
expect(testFunction).to.throw(InvalidValueError);
|
||||
});
|
||||
|
||||
it("encode invalid value", async function () {
|
||||
const value = "invalid"
|
||||
var testFunction = function () {
|
||||
const result = dpt.encoder(value)
|
||||
}
|
||||
expect(testFunction).to.throw(InvalidValueError);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user