From 8d08909a1fb719e082c26f76bb06bbe6bc4aafac Mon Sep 17 00:00:00 2001 From: "Dr Mark C. Sinclair" Date: Thu, 28 Nov 2024 07:41:17 +0000 Subject: [PATCH 01/20] chore(common/web): initial commit with incomplete first test case for write() --- .../types/test/kvk/test-kvk-file-writer.ts | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 common/web/types/test/kvk/test-kvk-file-writer.ts diff --git a/common/web/types/test/kvk/test-kvk-file-writer.ts b/common/web/types/test/kvk/test-kvk-file-writer.ts new file mode 100644 index 00000000000..476a511f466 --- /dev/null +++ b/common/web/types/test/kvk/test-kvk-file-writer.ts @@ -0,0 +1,39 @@ +/* + * Keyman is copyright (C) SIL Global. MIT License. + * + * Created by Dr Mark C. Sinclair on 2024-11-28 + * + * Test code for kvk-file-writer.ts + */ + +import 'mocha'; +import { assert } from 'chai'; +import { KvkFileWriter } from '../../src/main.js'; +import { VisualKeyboard, VisualKeyboardKey, DEFAULT_KVK_FONT } from '../../src/kvk/visual-keyboard.js'; +import { BUILDER_KVK_HEADER_FLAGS } from '../../src/kvk/kvk-file.js'; + +describe('Test of KVK-File-Writer', () => { + describe('Test of write()', () => { + it('can create a visual keyboard', () => { + const writer = new KvkFileWriter; + const vk = initVisualKeyboard(); + const file = writer.write(vk); + assert.isNotNull(file); + }); + }); +}); + +function initVisualKeyboard(): VisualKeyboard { + const vkh = { + // version?: number, + flags: BUILDER_KVK_HEADER_FLAGS.kvkhNone, + // associatedKeyboard?: string, + ansiFont: DEFAULT_KVK_FONT, + unicodeFont: DEFAULT_KVK_FONT, + // underlyingLayout?: string, + }; + const vkks: VisualKeyboardKey[] = []; + const vk: VisualKeyboard = { header: vkh, keys: vkks }; + return vk; +}; + From aac97cd8b9d08cf5feeddac38b349d32cbc0d3d1 Mon Sep 17 00:00:00 2001 From: "Dr Mark C. Sinclair" Date: Thu, 28 Nov 2024 08:02:48 +0000 Subject: [PATCH 02/20] chore(common/web): add one test case for setString() --- .../types/test/kvk/test-kvk-file-writer.ts | 49 ++++++++++++------- 1 file changed, 30 insertions(+), 19 deletions(-) diff --git a/common/web/types/test/kvk/test-kvk-file-writer.ts b/common/web/types/test/kvk/test-kvk-file-writer.ts index 476a511f466..ffd9e029dca 100644 --- a/common/web/types/test/kvk/test-kvk-file-writer.ts +++ b/common/web/types/test/kvk/test-kvk-file-writer.ts @@ -9,31 +9,42 @@ import 'mocha'; import { assert } from 'chai'; import { KvkFileWriter } from '../../src/main.js'; -import { VisualKeyboard, VisualKeyboardKey, DEFAULT_KVK_FONT } from '../../src/kvk/visual-keyboard.js'; -import { BUILDER_KVK_HEADER_FLAGS } from '../../src/kvk/kvk-file.js'; +//import { VisualKeyboard, VisualKeyboardKey, DEFAULT_KVK_FONT } from '../../src/kvk/visual-keyboard.js'; +//import { BUILDER_KVK_HEADER_FLAGS } from '../../src/kvk/kvk-file.js'; +import { BUILDER_KVK_STRING } from '../../src/kvk/kvk-file.js'; describe('Test of KVK-File-Writer', () => { describe('Test of write()', () => { - it('can create a visual keyboard', () => { + // it('can create a visual keyboard', () => { + // const writer = new KvkFileWriter; + // const vk = initVisualKeyboard(); + // const file = writer.write(vk); + // assert.isNotNull(file); + // }); + }); + describe('Test of setString()', () => { + it('can set a BUILDER_KVK_STRING', () => { + const bks: BUILDER_KVK_STRING = { len: 0, str: null }; const writer = new KvkFileWriter; - const vk = initVisualKeyboard(); - const file = writer.write(vk); - assert.isNotNull(file); + const str = "hello"; + writer['setString'](bks, str); + assert.equal(bks.len, str.length + 1); + assert.deepEqual(bks.str, str); }); }); }); -function initVisualKeyboard(): VisualKeyboard { - const vkh = { - // version?: number, - flags: BUILDER_KVK_HEADER_FLAGS.kvkhNone, - // associatedKeyboard?: string, - ansiFont: DEFAULT_KVK_FONT, - unicodeFont: DEFAULT_KVK_FONT, - // underlyingLayout?: string, - }; - const vkks: VisualKeyboardKey[] = []; - const vk: VisualKeyboard = { header: vkh, keys: vkks }; - return vk; -}; +// function initVisualKeyboard(): VisualKeyboard { +// const vkh = { +// // version?: number, +// flags: BUILDER_KVK_HEADER_FLAGS.kvkhNone, +// // associatedKeyboard?: string, +// ansiFont: DEFAULT_KVK_FONT, +// unicodeFont: DEFAULT_KVK_FONT, +// // underlyingLayout?: string, +// }; +// const vkks: VisualKeyboardKey[] = []; +// const vk: VisualKeyboard = { header: vkh, keys: vkks }; +// return vk; +// }; From 33056f0ec1c5fdab74cbbeac0fecc3738e3fe734 Mon Sep 17 00:00:00 2001 From: "Dr Mark C. Sinclair" Date: Thu, 28 Nov 2024 08:56:23 +0000 Subject: [PATCH 03/20] chore(common/web): incomplete test case for build() ... keys still needed --- .../types/test/kvk/test-kvk-file-writer.ts | 59 ++++++++++++++----- 1 file changed, 43 insertions(+), 16 deletions(-) diff --git a/common/web/types/test/kvk/test-kvk-file-writer.ts b/common/web/types/test/kvk/test-kvk-file-writer.ts index ffd9e029dca..f498733c7cc 100644 --- a/common/web/types/test/kvk/test-kvk-file-writer.ts +++ b/common/web/types/test/kvk/test-kvk-file-writer.ts @@ -9,9 +9,15 @@ import 'mocha'; import { assert } from 'chai'; import { KvkFileWriter } from '../../src/main.js'; -//import { VisualKeyboard, VisualKeyboardKey, DEFAULT_KVK_FONT } from '../../src/kvk/visual-keyboard.js'; -//import { BUILDER_KVK_HEADER_FLAGS } from '../../src/kvk/kvk-file.js'; -import { BUILDER_KVK_STRING } from '../../src/kvk/kvk-file.js'; +import { VisualKeyboard, VisualKeyboardKey, DEFAULT_KVK_FONT } from '../../src/kvk/visual-keyboard.js'; +import { BUILDER_KVK_FILE, + BUILDER_KVK_HEADER_FLAGS, + BUILDER_KVK_STRING, + BUILDER_KVK_HEADER_IDENTIFIER, + BUILDER_KVK_HEADER_VERSION, +} from '../../src/kvk/kvk-file.js'; + +const VISUAL_KEYBOARD_TEXT_COLOR = 0xFF000008; describe('Test of KVK-File-Writer', () => { describe('Test of write()', () => { @@ -22,6 +28,27 @@ describe('Test of KVK-File-Writer', () => { // assert.isNotNull(file); // }); }); + describe('Test of build()', () => { + it('can build a BUILDER_KVK_FILE', () => { + const vk = initVisualKeyboard(); + const writer = new KvkFileWriter; + const binary: BUILDER_KVK_FILE = writer['build'](vk); + assert.equal(binary.header.identifier, BUILDER_KVK_HEADER_IDENTIFIER); + assert.equal(binary.header.version, BUILDER_KVK_HEADER_VERSION); + assert.deepEqual(binary.header.associatedKeyboard.str, vk.header.associatedKeyboard); + assert.equal(binary.header.flags, BUILDER_KVK_HEADER_FLAGS.kvkhNone); + assert.deepEqual(binary.header.ansiFont, { + color: VISUAL_KEYBOARD_TEXT_COLOR, + size: vk.header.ansiFont.size, + name: { len: vk.header.ansiFont.name.length + 1, str: vk.header.ansiFont.name }, + }); + assert.deepEqual(binary.header.unicodeFont, { + color: VISUAL_KEYBOARD_TEXT_COLOR, + size: vk.header.unicodeFont.size, + name: { len: vk.header.ansiFont.name.length + 1, str: vk.header.ansiFont.name }, + }); + }); + }); describe('Test of setString()', () => { it('can set a BUILDER_KVK_STRING', () => { const bks: BUILDER_KVK_STRING = { len: 0, str: null }; @@ -34,17 +61,17 @@ describe('Test of KVK-File-Writer', () => { }); }); -// function initVisualKeyboard(): VisualKeyboard { -// const vkh = { -// // version?: number, -// flags: BUILDER_KVK_HEADER_FLAGS.kvkhNone, -// // associatedKeyboard?: string, -// ansiFont: DEFAULT_KVK_FONT, -// unicodeFont: DEFAULT_KVK_FONT, -// // underlyingLayout?: string, -// }; -// const vkks: VisualKeyboardKey[] = []; -// const vk: VisualKeyboard = { header: vkh, keys: vkks }; -// return vk; -// }; +function initVisualKeyboard(): VisualKeyboard { + const vkh = { + // version?: number, + flags: BUILDER_KVK_HEADER_FLAGS.kvkhNone, + associatedKeyboard: "associatedKeyboard", + ansiFont: DEFAULT_KVK_FONT, + unicodeFont: DEFAULT_KVK_FONT, + // underlyingLayout?: string, + }; + const vkks: VisualKeyboardKey[] = []; + const vk: VisualKeyboard = { header: vkh, keys: vkks }; + return vk; +}; From 4f21cde8aecd58726e70929245ed184aadcac842 Mon Sep 17 00:00:00 2001 From: "Dr Mark C. Sinclair" Date: Fri, 29 Nov 2024 06:04:10 +0000 Subject: [PATCH 04/20] chore(common/web): also check keys as part of initial build test case --- .../types/test/kvk/test-kvk-file-writer.ts | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/common/web/types/test/kvk/test-kvk-file-writer.ts b/common/web/types/test/kvk/test-kvk-file-writer.ts index f498733c7cc..e64b3eb9e97 100644 --- a/common/web/types/test/kvk/test-kvk-file-writer.ts +++ b/common/web/types/test/kvk/test-kvk-file-writer.ts @@ -15,6 +15,8 @@ import { BUILDER_KVK_FILE, BUILDER_KVK_STRING, BUILDER_KVK_HEADER_IDENTIFIER, BUILDER_KVK_HEADER_VERSION, + BUILDER_KVK_KEY_FLAGS, + BUILDER_KVK_SHIFT_STATE, } from '../../src/kvk/kvk-file.js'; const VISUAL_KEYBOARD_TEXT_COLOR = 0xFF000008; @@ -47,6 +49,14 @@ describe('Test of KVK-File-Writer', () => { size: vk.header.unicodeFont.size, name: { len: vk.header.ansiFont.name.length + 1, str: vk.header.ansiFont.name }, }); + vk.keys.forEach((vkk, idx) => { + assert.equal(binary.keys[idx].flags, vkk.flags); + assert.equal(binary.keys[idx].shift, vkk.shift); + assert.equal(binary.keys[idx].vkey, vkk.vkey); + assert.deepEqual(binary.keys[idx].text.str, vkk.text); + assert.equal(binary.keys[idx].bitmapSize, vkk.bitmap.byteLength); + assert.deepEqual(Array.from(vkk.bitmap), [idx]); + }); }); }); describe('Test of setString()', () => { @@ -70,8 +80,23 @@ function initVisualKeyboard(): VisualKeyboard { unicodeFont: DEFAULT_KVK_FONT, // underlyingLayout?: string, }; + const vkks: VisualKeyboardKey[] = []; + for (let i=0; i<3; i++) { + initVisualKeyboardKey(i); + } + const vk: VisualKeyboard = { header: vkh, keys: vkks }; return vk; }; +function initVisualKeyboardKey(index: number): VisualKeyboardKey { + const vkk: VisualKeyboardKey = { + flags: BUILDER_KVK_KEY_FLAGS.kvkkBitmap, + shift: BUILDER_KVK_SHIFT_STATE.KVKS_NORMAL, + vkey: index, + text: "text", + bitmap: new Uint8Array([index]), + }; + return vkk; +} From 7a462cff4d1c280e914f53f9d64051462c2bcb7d Mon Sep 17 00:00:00 2001 From: "Dr Mark C. Sinclair" Date: Fri, 29 Nov 2024 06:10:52 +0000 Subject: [PATCH 05/20] chore(common/web): uncommented initial test case on write() now initVisualKeyboard() is no longer incomplete --- common/web/types/test/kvk/test-kvk-file-writer.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/common/web/types/test/kvk/test-kvk-file-writer.ts b/common/web/types/test/kvk/test-kvk-file-writer.ts index e64b3eb9e97..067ee80c390 100644 --- a/common/web/types/test/kvk/test-kvk-file-writer.ts +++ b/common/web/types/test/kvk/test-kvk-file-writer.ts @@ -23,12 +23,12 @@ const VISUAL_KEYBOARD_TEXT_COLOR = 0xFF000008; describe('Test of KVK-File-Writer', () => { describe('Test of write()', () => { - // it('can create a visual keyboard', () => { - // const writer = new KvkFileWriter; - // const vk = initVisualKeyboard(); - // const file = writer.write(vk); - // assert.isNotNull(file); - // }); + it('can create a visual keyboard', () => { + const writer = new KvkFileWriter; + const vk = initVisualKeyboard(); + const file = writer.write(vk); + assert.isNotNull(file); + }); }); describe('Test of build()', () => { it('can build a BUILDER_KVK_FILE', () => { From 7e024d24904696e63524644d27d9224fcef04066 Mon Sep 17 00:00:00 2001 From: "Dr Mark C. Sinclair" Date: Fri, 29 Nov 2024 06:52:17 +0000 Subject: [PATCH 06/20] chore(common/web): add more flexibility in setting up keys via initVisualKeyboardKey() --- .../types/test/kvk/test-kvk-file-writer.ts | 35 +++++++++++-------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/common/web/types/test/kvk/test-kvk-file-writer.ts b/common/web/types/test/kvk/test-kvk-file-writer.ts index 067ee80c390..28186843c88 100644 --- a/common/web/types/test/kvk/test-kvk-file-writer.ts +++ b/common/web/types/test/kvk/test-kvk-file-writer.ts @@ -25,14 +25,22 @@ describe('Test of KVK-File-Writer', () => { describe('Test of write()', () => { it('can create a visual keyboard', () => { const writer = new KvkFileWriter; - const vk = initVisualKeyboard(); - const file = writer.write(vk); + const vk = initVisualKeyboard([ + initVisualKeyboardKey(0), + initVisualKeyboardKey(1), + initVisualKeyboardKey(2), + ]); + const file = writer.write(vk); assert.isNotNull(file); }); }); describe('Test of build()', () => { it('can build a BUILDER_KVK_FILE', () => { - const vk = initVisualKeyboard(); + const vk = initVisualKeyboard([ + initVisualKeyboardKey(0), + initVisualKeyboardKey(1), + initVisualKeyboardKey(2), + ]); const writer = new KvkFileWriter; const binary: BUILDER_KVK_FILE = writer['build'](vk); assert.equal(binary.header.identifier, BUILDER_KVK_HEADER_IDENTIFIER); @@ -71,7 +79,7 @@ describe('Test of KVK-File-Writer', () => { }); }); -function initVisualKeyboard(): VisualKeyboard { +function initVisualKeyboard(vkks: VisualKeyboardKey[]): VisualKeyboard { const vkh = { // version?: number, flags: BUILDER_KVK_HEADER_FLAGS.kvkhNone, @@ -80,20 +88,17 @@ function initVisualKeyboard(): VisualKeyboard { unicodeFont: DEFAULT_KVK_FONT, // underlyingLayout?: string, }; - - const vkks: VisualKeyboardKey[] = []; - for (let i=0; i<3; i++) { - initVisualKeyboardKey(i); - } - - const vk: VisualKeyboard = { header: vkh, keys: vkks }; - return vk; + return { header: vkh, keys: vkks }; }; -function initVisualKeyboardKey(index: number): VisualKeyboardKey { +function initVisualKeyboardKey( + index: number, + flags: BUILDER_KVK_KEY_FLAGS = BUILDER_KVK_KEY_FLAGS.kvkkBitmap, + shift: BUILDER_KVK_SHIFT_STATE = BUILDER_KVK_SHIFT_STATE.KVKS_NORMAL, +): VisualKeyboardKey { const vkk: VisualKeyboardKey = { - flags: BUILDER_KVK_KEY_FLAGS.kvkkBitmap, - shift: BUILDER_KVK_SHIFT_STATE.KVKS_NORMAL, + flags: flags, + shift: shift, vkey: index, text: "text", bitmap: new Uint8Array([index]), From 027db4bfb193ff9da81a3c11d6be0ec7b15efa8c Mon Sep 17 00:00:00 2001 From: "Dr Mark C. Sinclair" Date: Fri, 29 Nov 2024 07:05:44 +0000 Subject: [PATCH 07/20] chore(common/web): add checkVisualKeyboardKey to compare source and binary keys --- .../types/test/kvk/test-kvk-file-writer.ts | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/common/web/types/test/kvk/test-kvk-file-writer.ts b/common/web/types/test/kvk/test-kvk-file-writer.ts index 28186843c88..4c0edca5232 100644 --- a/common/web/types/test/kvk/test-kvk-file-writer.ts +++ b/common/web/types/test/kvk/test-kvk-file-writer.ts @@ -15,6 +15,7 @@ import { BUILDER_KVK_FILE, BUILDER_KVK_STRING, BUILDER_KVK_HEADER_IDENTIFIER, BUILDER_KVK_HEADER_VERSION, + BUILDER_KVK_KEY, BUILDER_KVK_KEY_FLAGS, BUILDER_KVK_SHIFT_STATE, } from '../../src/kvk/kvk-file.js'; @@ -57,14 +58,9 @@ describe('Test of KVK-File-Writer', () => { size: vk.header.unicodeFont.size, name: { len: vk.header.ansiFont.name.length + 1, str: vk.header.ansiFont.name }, }); - vk.keys.forEach((vkk, idx) => { - assert.equal(binary.keys[idx].flags, vkk.flags); - assert.equal(binary.keys[idx].shift, vkk.shift); - assert.equal(binary.keys[idx].vkey, vkk.vkey); - assert.deepEqual(binary.keys[idx].text.str, vkk.text); - assert.equal(binary.keys[idx].bitmapSize, vkk.bitmap.byteLength); - assert.deepEqual(Array.from(vkk.bitmap), [idx]); - }); + for (let idx=0; idx { @@ -105,3 +101,12 @@ function initVisualKeyboardKey( }; return vkk; } + +function checkVisualKeyboardKey(target: BUILDER_KVK_KEY, source: VisualKeyboardKey) { + assert.equal(target.flags, source.flags); + assert.equal(target.shift, source.shift); + assert.equal(target.vkey, source.vkey); + assert.deepEqual(target.text.str, source.text); + assert.equal(target.bitmapSize, source.bitmap.byteLength); + assert.deepEqual(target.bitmapData, Array.from(source.bitmap)); +} \ No newline at end of file From bbc8fa763b25d4110678428cd84b29a2dd723210 Mon Sep 17 00:00:00 2001 From: "Dr Mark C. Sinclair" Date: Fri, 29 Nov 2024 07:19:42 +0000 Subject: [PATCH 08/20] chore(common/web): add checkBuilderKvkFile() to compare source and binary keyboards --- .../types/test/kvk/test-kvk-file-writer.ts | 40 ++++++++++--------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/common/web/types/test/kvk/test-kvk-file-writer.ts b/common/web/types/test/kvk/test-kvk-file-writer.ts index 4c0edca5232..3c8c0e9e6ed 100644 --- a/common/web/types/test/kvk/test-kvk-file-writer.ts +++ b/common/web/types/test/kvk/test-kvk-file-writer.ts @@ -44,23 +44,7 @@ describe('Test of KVK-File-Writer', () => { ]); const writer = new KvkFileWriter; const binary: BUILDER_KVK_FILE = writer['build'](vk); - assert.equal(binary.header.identifier, BUILDER_KVK_HEADER_IDENTIFIER); - assert.equal(binary.header.version, BUILDER_KVK_HEADER_VERSION); - assert.deepEqual(binary.header.associatedKeyboard.str, vk.header.associatedKeyboard); - assert.equal(binary.header.flags, BUILDER_KVK_HEADER_FLAGS.kvkhNone); - assert.deepEqual(binary.header.ansiFont, { - color: VISUAL_KEYBOARD_TEXT_COLOR, - size: vk.header.ansiFont.size, - name: { len: vk.header.ansiFont.name.length + 1, str: vk.header.ansiFont.name }, - }); - assert.deepEqual(binary.header.unicodeFont, { - color: VISUAL_KEYBOARD_TEXT_COLOR, - size: vk.header.unicodeFont.size, - name: { len: vk.header.ansiFont.name.length + 1, str: vk.header.ansiFont.name }, - }); - for (let idx=0; idx { @@ -102,7 +86,27 @@ function initVisualKeyboardKey( return vkk; } -function checkVisualKeyboardKey(target: BUILDER_KVK_KEY, source: VisualKeyboardKey) { +function checkBuilderKvkFile(binary: BUILDER_KVK_FILE, vk: VisualKeyboard) { + assert.equal(binary.header.identifier, BUILDER_KVK_HEADER_IDENTIFIER); + assert.equal(binary.header.version, BUILDER_KVK_HEADER_VERSION); + assert.deepEqual(binary.header.associatedKeyboard.str, vk.header.associatedKeyboard); + assert.equal(binary.header.flags, vk.header.flags); + assert.deepEqual(binary.header.ansiFont, { + color: VISUAL_KEYBOARD_TEXT_COLOR, + size: vk.header.ansiFont.size, + name: { len: vk.header.ansiFont.name.length + 1, str: vk.header.ansiFont.name }, + }); + assert.deepEqual(binary.header.unicodeFont, { + color: VISUAL_KEYBOARD_TEXT_COLOR, + size: vk.header.unicodeFont.size, + name: { len: vk.header.ansiFont.name.length + 1, str: vk.header.ansiFont.name }, + }); + for (let idx=0; idx Date: Fri, 29 Nov 2024 07:26:42 +0000 Subject: [PATCH 09/20] chore(common/web): simplify checks on fonts in checkBuilderKvkFile --- .../web/types/test/kvk/test-kvk-file-writer.ts | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/common/web/types/test/kvk/test-kvk-file-writer.ts b/common/web/types/test/kvk/test-kvk-file-writer.ts index 3c8c0e9e6ed..af3fb95756f 100644 --- a/common/web/types/test/kvk/test-kvk-file-writer.ts +++ b/common/web/types/test/kvk/test-kvk-file-writer.ts @@ -91,16 +91,12 @@ function checkBuilderKvkFile(binary: BUILDER_KVK_FILE, vk: VisualKeyboard) { assert.equal(binary.header.version, BUILDER_KVK_HEADER_VERSION); assert.deepEqual(binary.header.associatedKeyboard.str, vk.header.associatedKeyboard); assert.equal(binary.header.flags, vk.header.flags); - assert.deepEqual(binary.header.ansiFont, { - color: VISUAL_KEYBOARD_TEXT_COLOR, - size: vk.header.ansiFont.size, - name: { len: vk.header.ansiFont.name.length + 1, str: vk.header.ansiFont.name }, - }); - assert.deepEqual(binary.header.unicodeFont, { - color: VISUAL_KEYBOARD_TEXT_COLOR, - size: vk.header.unicodeFont.size, - name: { len: vk.header.ansiFont.name.length + 1, str: vk.header.ansiFont.name }, - }); + assert.equal(binary.header.ansiFont.color, VISUAL_KEYBOARD_TEXT_COLOR); + assert.equal(binary.header.ansiFont.size, vk.header.ansiFont.size); + assert.deepEqual(binary.header.ansiFont.name.str, vk.header.ansiFont.name); + assert.equal(binary.header.unicodeFont.color, VISUAL_KEYBOARD_TEXT_COLOR); + assert.equal(binary.header.unicodeFont.size, vk.header.unicodeFont.size); + assert.deepEqual(binary.header.unicodeFont.name.str, vk.header.unicodeFont.name); for (let idx=0; idx Date: Fri, 29 Nov 2024 07:37:09 +0000 Subject: [PATCH 10/20] chore(common/web): added greater flexibility via optional parameters to initVisualKeyboard() --- .../types/test/kvk/test-kvk-file-writer.ts | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/common/web/types/test/kvk/test-kvk-file-writer.ts b/common/web/types/test/kvk/test-kvk-file-writer.ts index af3fb95756f..78df4dfbf69 100644 --- a/common/web/types/test/kvk/test-kvk-file-writer.ts +++ b/common/web/types/test/kvk/test-kvk-file-writer.ts @@ -9,7 +9,11 @@ import 'mocha'; import { assert } from 'chai'; import { KvkFileWriter } from '../../src/main.js'; -import { VisualKeyboard, VisualKeyboardKey, DEFAULT_KVK_FONT } from '../../src/kvk/visual-keyboard.js'; +import { VisualKeyboard, + VisualKeyboardKey, + VisualKeyboardFont, + DEFAULT_KVK_FONT +} from '../../src/kvk/visual-keyboard.js'; import { BUILDER_KVK_FILE, BUILDER_KVK_HEADER_FLAGS, BUILDER_KVK_STRING, @@ -59,13 +63,19 @@ describe('Test of KVK-File-Writer', () => { }); }); -function initVisualKeyboard(vkks: VisualKeyboardKey[]): VisualKeyboard { +function initVisualKeyboard( + vkks: VisualKeyboardKey[], + flags: BUILDER_KVK_HEADER_FLAGS = BUILDER_KVK_HEADER_FLAGS.kvkhNone, + associatedKeyboard: string = "associatedKeyboard", + ansiFont: VisualKeyboardFont = DEFAULT_KVK_FONT, + unicodeFont: VisualKeyboardFont = DEFAULT_KVK_FONT, +): VisualKeyboard { const vkh = { // version?: number, - flags: BUILDER_KVK_HEADER_FLAGS.kvkhNone, - associatedKeyboard: "associatedKeyboard", - ansiFont: DEFAULT_KVK_FONT, - unicodeFont: DEFAULT_KVK_FONT, + flags: flags, + associatedKeyboard: associatedKeyboard, + ansiFont: ansiFont, + unicodeFont: unicodeFont, // underlyingLayout?: string, }; return { header: vkh, keys: vkks }; From db31ed08943b2db0f0cb09b4ba711b09492cdd8a Mon Sep 17 00:00:00 2001 From: "Dr Mark C. Sinclair" Date: Fri, 29 Nov 2024 07:57:28 +0000 Subject: [PATCH 11/20] chore(common/web): add two test cases for null parameters to setString() --- common/web/types/test/kvk/test-kvk-file-writer.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/common/web/types/test/kvk/test-kvk-file-writer.ts b/common/web/types/test/kvk/test-kvk-file-writer.ts index 78df4dfbf69..1dd15b9d5cf 100644 --- a/common/web/types/test/kvk/test-kvk-file-writer.ts +++ b/common/web/types/test/kvk/test-kvk-file-writer.ts @@ -60,6 +60,19 @@ describe('Test of KVK-File-Writer', () => { assert.equal(bks.len, str.length + 1); assert.deepEqual(bks.str, str); }); + it('throws TypeError for a null BUILDER_KVK_STRING', () => { + assert.throws(() => { + const writer = new KvkFileWriter; + writer['setString'](null, ""); + }, TypeError); + }); + it('throws TypeError for a null value', () => { + assert.throws(() => { + const bks: BUILDER_KVK_STRING = { len: 0, str: null }; + const writer = new KvkFileWriter; + writer['setString'](bks, null); + }, TypeError); + }); }); }); From 2493e2bc857597c75683f83dbcacd3686020b622 Mon Sep 17 00:00:00 2001 From: "Dr Mark C. Sinclair" Date: Tue, 3 Dec 2024 12:26:08 +0000 Subject: [PATCH 12/20] chore(common/web): add three commented-out build() test cases for null strings that would currently fail --- .../types/test/kvk/test-kvk-file-writer.ts | 63 ++++++++++++++++++- 1 file changed, 60 insertions(+), 3 deletions(-) diff --git a/common/web/types/test/kvk/test-kvk-file-writer.ts b/common/web/types/test/kvk/test-kvk-file-writer.ts index 1dd15b9d5cf..2bffbcdb544 100644 --- a/common/web/types/test/kvk/test-kvk-file-writer.ts +++ b/common/web/types/test/kvk/test-kvk-file-writer.ts @@ -50,6 +50,51 @@ describe('Test of KVK-File-Writer', () => { const binary: BUILDER_KVK_FILE = writer['build'](vk); checkBuilderKvkFile(binary, vk); }); + // it('can handle a null associatedKeyboard', () => { + // const vk = initVisualKeyboard([ + // initVisualKeyboardKey(0), + // initVisualKeyboardKey(1), + // initVisualKeyboardKey(2), + // ], + // BUILDER_KVK_HEADER_FLAGS.kvkhNone, + // null, + // DEFAULT_KVK_FONT, + // DEFAULT_KVK_FONT, + // ); + // const writer = new KvkFileWriter; + // const binary: BUILDER_KVK_FILE = writer['build'](vk); + // checkBuilderKvkFile(binary, vk); + // }); + // it('can handle a null ansiFont name', () => { + // const vk = initVisualKeyboard([ + // initVisualKeyboardKey(0), + // initVisualKeyboardKey(1), + // initVisualKeyboardKey(2), + // ], + // BUILDER_KVK_HEADER_FLAGS.kvkhNone, + // "associatedKeyboard", + // { name: null, size: -12 }, + // DEFAULT_KVK_FONT, + // ); + // const writer = new KvkFileWriter; + // const binary: BUILDER_KVK_FILE = writer['build'](vk); + // checkBuilderKvkFile(binary, vk); + // }); + // it('can handle a null unicodeFont name', () => { + // const vk = initVisualKeyboard([ + // initVisualKeyboardKey(0), + // initVisualKeyboardKey(1), + // initVisualKeyboardKey(2), + // ], + // BUILDER_KVK_HEADER_FLAGS.kvkhNone, + // "associatedKeyboard", + // DEFAULT_KVK_FONT, + // { name: null, size: -12 }, + // ); + // const writer = new KvkFileWriter; + // const binary: BUILDER_KVK_FILE = writer['build'](vk); + // checkBuilderKvkFile(binary, vk); + // }); }); describe('Test of setString()', () => { it('can set a BUILDER_KVK_STRING', () => { @@ -112,14 +157,26 @@ function initVisualKeyboardKey( function checkBuilderKvkFile(binary: BUILDER_KVK_FILE, vk: VisualKeyboard) { assert.equal(binary.header.identifier, BUILDER_KVK_HEADER_IDENTIFIER); assert.equal(binary.header.version, BUILDER_KVK_HEADER_VERSION); - assert.deepEqual(binary.header.associatedKeyboard.str, vk.header.associatedKeyboard); + if (vk.header.associatedKeyboard != null) { + assert.deepEqual(binary.header.associatedKeyboard.str, vk.header.associatedKeyboard); + } else { + assert.deepEqual(binary.header.associatedKeyboard.str, ''); + } assert.equal(binary.header.flags, vk.header.flags); assert.equal(binary.header.ansiFont.color, VISUAL_KEYBOARD_TEXT_COLOR); assert.equal(binary.header.ansiFont.size, vk.header.ansiFont.size); - assert.deepEqual(binary.header.ansiFont.name.str, vk.header.ansiFont.name); + if (vk.header.ansiFont.name != null) { + assert.deepEqual(binary.header.ansiFont.name.str, vk.header.ansiFont.name); + } else { + assert.deepEqual(binary.header.ansiFont.name.str, ''); + } assert.equal(binary.header.unicodeFont.color, VISUAL_KEYBOARD_TEXT_COLOR); assert.equal(binary.header.unicodeFont.size, vk.header.unicodeFont.size); - assert.deepEqual(binary.header.unicodeFont.name.str, vk.header.unicodeFont.name); + if (vk.header.unicodeFont.name != null) { + assert.deepEqual(binary.header.unicodeFont.name.str, vk.header.unicodeFont.name); + } else { + assert.deepEqual(binary.header.unicodeFont.name.str, ''); + } for (let idx=0; idx Date: Tue, 3 Dec 2024 12:38:55 +0000 Subject: [PATCH 13/20] chore(common/web): adjust initVisualKeyboardKey() and checkBuilderKvkKey() to cope with some null inputs --- .../types/test/kvk/test-kvk-file-writer.ts | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/common/web/types/test/kvk/test-kvk-file-writer.ts b/common/web/types/test/kvk/test-kvk-file-writer.ts index 2bffbcdb544..b4b4bc57ecc 100644 --- a/common/web/types/test/kvk/test-kvk-file-writer.ts +++ b/common/web/types/test/kvk/test-kvk-file-writer.ts @@ -141,15 +141,17 @@ function initVisualKeyboard( function initVisualKeyboardKey( index: number, - flags: BUILDER_KVK_KEY_FLAGS = BUILDER_KVK_KEY_FLAGS.kvkkBitmap, + flags: BUILDER_KVK_KEY_FLAGS = BUILDER_KVK_KEY_FLAGS.kvkkBitmap, shift: BUILDER_KVK_SHIFT_STATE = BUILDER_KVK_SHIFT_STATE.KVKS_NORMAL, + text: string = "text", + bitmap: number[] = null, ): VisualKeyboardKey { const vkk: VisualKeyboardKey = { flags: flags, shift: shift, vkey: index, - text: "text", - bitmap: new Uint8Array([index]), + text: text, + bitmap: bitmap ? new Uint8Array(bitmap) : null, }; return vkk; } @@ -186,7 +188,16 @@ function checkBuilderKvkKey(target: BUILDER_KVK_KEY, source: VisualKeyboardKey) assert.equal(target.flags, source.flags); assert.equal(target.shift, source.shift); assert.equal(target.vkey, source.vkey); - assert.deepEqual(target.text.str, source.text); - assert.equal(target.bitmapSize, source.bitmap.byteLength); - assert.deepEqual(target.bitmapData, Array.from(source.bitmap)); + if (source.text != null) { + assert.deepEqual(target.text.str, source.text); + } else { + assert.deepEqual(target.text.str, ''); + } + if (source.bitmap != null) { + assert.equal(target.bitmapSize, source.bitmap.byteLength); + assert.deepEqual(target.bitmapData, Array.from(source.bitmap)); + } else { + assert.equal(target.bitmapSize, 0); + assert.deepEqual(target.bitmapData, []); + } } \ No newline at end of file From 47794cfe21be19ca1fd8fc752aff21d3b3722595 Mon Sep 17 00:00:00 2001 From: "Dr Mark C. Sinclair" Date: Tue, 3 Dec 2024 12:54:40 +0000 Subject: [PATCH 14/20] chore(common/web): add two test cases for null key text and non-null key bitmap --- .../types/test/kvk/test-kvk-file-writer.ts | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/common/web/types/test/kvk/test-kvk-file-writer.ts b/common/web/types/test/kvk/test-kvk-file-writer.ts index b4b4bc57ecc..ef35064f786 100644 --- a/common/web/types/test/kvk/test-kvk-file-writer.ts +++ b/common/web/types/test/kvk/test-kvk-file-writer.ts @@ -95,6 +95,38 @@ describe('Test of KVK-File-Writer', () => { // const binary: BUILDER_KVK_FILE = writer['build'](vk); // checkBuilderKvkFile(binary, vk); // }); + it('can handle a null key text', () => { + const vk = initVisualKeyboard([ + initVisualKeyboardKey( + 0, + BUILDER_KVK_KEY_FLAGS.kvkkBitmap, + BUILDER_KVK_SHIFT_STATE.KVKS_NORMAL, + null, + null, + ), + initVisualKeyboardKey(1), + initVisualKeyboardKey(2), + ]); + const writer = new KvkFileWriter; + const binary: BUILDER_KVK_FILE = writer['build'](vk); + checkBuilderKvkFile(binary, vk); + }); + it('can handle a non-null key bitmap', () => { + const vk = initVisualKeyboard([ + initVisualKeyboardKey( + 0, + BUILDER_KVK_KEY_FLAGS.kvkkBitmap, + BUILDER_KVK_SHIFT_STATE.KVKS_NORMAL, + "text", + [0], + ), + initVisualKeyboardKey(1), + initVisualKeyboardKey(2), + ]); + const writer = new KvkFileWriter; + const binary: BUILDER_KVK_FILE = writer['build'](vk); + checkBuilderKvkFile(binary, vk); + }); }); describe('Test of setString()', () => { it('can set a BUILDER_KVK_STRING', () => { From 27b7fc33a265722708a07788258d808e1d5d1715 Mon Sep 17 00:00:00 2001 From: "Dr Mark C. Sinclair" Date: Thu, 5 Dec 2024 11:02:19 +0000 Subject: [PATCH 15/20] chore(common/web): add test case for empty string for setString() --- common/web/types/tests/kvk/kvk-file-writer.tests.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/common/web/types/tests/kvk/kvk-file-writer.tests.ts b/common/web/types/tests/kvk/kvk-file-writer.tests.ts index ef35064f786..0549724adf8 100644 --- a/common/web/types/tests/kvk/kvk-file-writer.tests.ts +++ b/common/web/types/tests/kvk/kvk-file-writer.tests.ts @@ -137,6 +137,14 @@ describe('Test of KVK-File-Writer', () => { assert.equal(bks.len, str.length + 1); assert.deepEqual(bks.str, str); }); + it('can handle an empty string', () => { + const bks: BUILDER_KVK_STRING = { len: 0, str: null }; + const writer = new KvkFileWriter; + const str = ""; + writer['setString'](bks, str); + assert.equal(bks.len, str.length + 1); + assert.deepEqual(bks.str, str); + }); it('throws TypeError for a null BUILDER_KVK_STRING', () => { assert.throws(() => { const writer = new KvkFileWriter; From 7a19de8b86d908d7ccbdce0143767ea58e75fd2f Mon Sep 17 00:00:00 2001 From: "Dr Mark C. Sinclair" Date: Thu, 5 Dec 2024 11:56:00 +0000 Subject: [PATCH 16/20] chore(common/web): add four additional test cases wrt VisualKeyboard version and null values --- .../types/tests/kvk/kvk-file-writer.tests.ts | 135 ++++++++++++++---- 1 file changed, 104 insertions(+), 31 deletions(-) diff --git a/common/web/types/tests/kvk/kvk-file-writer.tests.ts b/common/web/types/tests/kvk/kvk-file-writer.tests.ts index 0549724adf8..e756ee28af3 100644 --- a/common/web/types/tests/kvk/kvk-file-writer.tests.ts +++ b/common/web/types/tests/kvk/kvk-file-writer.tests.ts @@ -50,51 +50,122 @@ describe('Test of KVK-File-Writer', () => { const binary: BUILDER_KVK_FILE = writer['build'](vk); checkBuilderKvkFile(binary, vk); }); + it('does not take account of the VisualKeyboard version', () => { + const vk = initVisualKeyboard([ + initVisualKeyboardKey(0), + initVisualKeyboardKey(1), + initVisualKeyboardKey(2), + ], + (BUILDER_KVK_HEADER_VERSION + 0x0100), + BUILDER_KVK_HEADER_FLAGS.kvkhNone, + "associatedKeyboard", + DEFAULT_KVK_FONT, + DEFAULT_KVK_FONT, + undefined, + ); + const writer = new KvkFileWriter; + const binary: BUILDER_KVK_FILE = writer['build'](vk); + checkBuilderKvkFile(binary, vk); + }); // it('can handle a null associatedKeyboard', () => { // const vk = initVisualKeyboard([ - // initVisualKeyboardKey(0), - // initVisualKeyboardKey(1), - // initVisualKeyboardKey(2), - // ], - // BUILDER_KVK_HEADER_FLAGS.kvkhNone, - // null, - // DEFAULT_KVK_FONT, - // DEFAULT_KVK_FONT, - // ); + // initVisualKeyboardKey(0), + // initVisualKeyboardKey(1), + // initVisualKeyboardKey(2), + // ], + // undefined, + // BUILDER_KVK_HEADER_FLAGS.kvkhNone, + // null, + // DEFAULT_KVK_FONT, + // DEFAULT_KVK_FONT, + // undefined, + // ); // const writer = new KvkFileWriter; // const binary: BUILDER_KVK_FILE = writer['build'](vk); // checkBuilderKvkFile(binary, vk); // }); // it('can handle a null ansiFont name', () => { // const vk = initVisualKeyboard([ - // initVisualKeyboardKey(0), - // initVisualKeyboardKey(1), - // initVisualKeyboardKey(2), - // ], - // BUILDER_KVK_HEADER_FLAGS.kvkhNone, - // "associatedKeyboard", - // { name: null, size: -12 }, - // DEFAULT_KVK_FONT, - // ); + // initVisualKeyboardKey(0), + // initVisualKeyboardKey(1), + // initVisualKeyboardKey(2), + // ], + // undefined, + // BUILDER_KVK_HEADER_FLAGS.kvkhNone, + // "associatedKeyboard", + // { name: null, size: -12 }, + // DEFAULT_KVK_FONT, + // undefined, + // ); // const writer = new KvkFileWriter; // const binary: BUILDER_KVK_FILE = writer['build'](vk); // checkBuilderKvkFile(binary, vk); // }); // it('can handle a null unicodeFont name', () => { // const vk = initVisualKeyboard([ - // initVisualKeyboardKey(0), - // initVisualKeyboardKey(1), - // initVisualKeyboardKey(2), - // ], - // BUILDER_KVK_HEADER_FLAGS.kvkhNone, - // "associatedKeyboard", - // DEFAULT_KVK_FONT, - // { name: null, size: -12 }, - // ); + // initVisualKeyboardKey(0), + // initVisualKeyboardKey(1), + // initVisualKeyboardKey(2), + // ], + // undefined, + // BUILDER_KVK_HEADER_FLAGS.kvkhNone, + // "associatedKeyboard", + // DEFAULT_KVK_FONT, + // { name: null, size: -12 }, + // undefined, + // ); // const writer = new KvkFileWriter; // const binary: BUILDER_KVK_FILE = writer['build'](vk); // checkBuilderKvkFile(binary, vk); // }); + it('can handle a null vkey', () => { + const vk = initVisualKeyboard([ + initVisualKeyboardKey( + null, + BUILDER_KVK_KEY_FLAGS.kvkkBitmap, + BUILDER_KVK_SHIFT_STATE.KVKS_NORMAL, + "text", + null, + ), + initVisualKeyboardKey(1), + initVisualKeyboardKey(2), + ]); + const writer = new KvkFileWriter; + const binary: BUILDER_KVK_FILE = writer['build'](vk); + checkBuilderKvkFile(binary, vk); + }); + it('can handle a null key flags', () => { + const vk = initVisualKeyboard([ + initVisualKeyboardKey( + 0, + null, + BUILDER_KVK_SHIFT_STATE.KVKS_NORMAL, + "text", + null, + ), + initVisualKeyboardKey(1), + initVisualKeyboardKey(2), + ]); + const writer = new KvkFileWriter; + const binary: BUILDER_KVK_FILE = writer['build'](vk); + checkBuilderKvkFile(binary, vk); + }); + it('can handle a null key shift', () => { + const vk = initVisualKeyboard([ + initVisualKeyboardKey( + 0, + BUILDER_KVK_KEY_FLAGS.kvkkBitmap, + null, + "text", + null, + ), + initVisualKeyboardKey(1), + initVisualKeyboardKey(2), + ]); + const writer = new KvkFileWriter; + const binary: BUILDER_KVK_FILE = writer['build'](vk); + checkBuilderKvkFile(binary, vk); + }); it('can handle a null key text', () => { const vk = initVisualKeyboard([ initVisualKeyboardKey( @@ -163,33 +234,35 @@ describe('Test of KVK-File-Writer', () => { function initVisualKeyboard( vkks: VisualKeyboardKey[], + version: number = undefined, flags: BUILDER_KVK_HEADER_FLAGS = BUILDER_KVK_HEADER_FLAGS.kvkhNone, associatedKeyboard: string = "associatedKeyboard", ansiFont: VisualKeyboardFont = DEFAULT_KVK_FONT, unicodeFont: VisualKeyboardFont = DEFAULT_KVK_FONT, + underlyingLayout: string = undefined, ): VisualKeyboard { const vkh = { - // version?: number, + version: version, flags: flags, associatedKeyboard: associatedKeyboard, ansiFont: ansiFont, unicodeFont: unicodeFont, - // underlyingLayout?: string, + underlyingLayout: underlyingLayout, }; return { header: vkh, keys: vkks }; }; function initVisualKeyboardKey( - index: number, + vkey: number, flags: BUILDER_KVK_KEY_FLAGS = BUILDER_KVK_KEY_FLAGS.kvkkBitmap, shift: BUILDER_KVK_SHIFT_STATE = BUILDER_KVK_SHIFT_STATE.KVKS_NORMAL, text: string = "text", bitmap: number[] = null, ): VisualKeyboardKey { const vkk: VisualKeyboardKey = { + vkey: vkey, flags: flags, shift: shift, - vkey: index, text: text, bitmap: bitmap ? new Uint8Array(bitmap) : null, }; From aad790a42b321ef2cb116ac99bfb61858e03601a Mon Sep 17 00:00:00 2001 From: "Dr Mark C. Sinclair" Date: Thu, 5 Dec 2024 11:56:00 +0000 Subject: [PATCH 17/20] chore(common/web): add four additional test cases wrt VisualKeyboard version and null values --- .../types/tests/kvk/kvk-file-writer.tests.ts | 137 ++++++++++++++---- 1 file changed, 105 insertions(+), 32 deletions(-) diff --git a/common/web/types/tests/kvk/kvk-file-writer.tests.ts b/common/web/types/tests/kvk/kvk-file-writer.tests.ts index 0549724adf8..cd386016c9c 100644 --- a/common/web/types/tests/kvk/kvk-file-writer.tests.ts +++ b/common/web/types/tests/kvk/kvk-file-writer.tests.ts @@ -1,7 +1,7 @@ /* * Keyman is copyright (C) SIL Global. MIT License. * - * Created by Dr Mark C. Sinclair on 2024-11-28 + * Created by Dr Mark C. Sinclair on 2024-12-05 * * Test code for kvk-file-writer.ts */ @@ -50,51 +50,122 @@ describe('Test of KVK-File-Writer', () => { const binary: BUILDER_KVK_FILE = writer['build'](vk); checkBuilderKvkFile(binary, vk); }); + it('does not take account of the VisualKeyboard version', () => { + const vk = initVisualKeyboard([ + initVisualKeyboardKey(0), + initVisualKeyboardKey(1), + initVisualKeyboardKey(2), + ], + (BUILDER_KVK_HEADER_VERSION + 0x0100), + BUILDER_KVK_HEADER_FLAGS.kvkhNone, + "associatedKeyboard", + DEFAULT_KVK_FONT, + DEFAULT_KVK_FONT, + undefined, + ); + const writer = new KvkFileWriter; + const binary: BUILDER_KVK_FILE = writer['build'](vk); + checkBuilderKvkFile(binary, vk); + }); // it('can handle a null associatedKeyboard', () => { // const vk = initVisualKeyboard([ - // initVisualKeyboardKey(0), - // initVisualKeyboardKey(1), - // initVisualKeyboardKey(2), - // ], - // BUILDER_KVK_HEADER_FLAGS.kvkhNone, - // null, - // DEFAULT_KVK_FONT, - // DEFAULT_KVK_FONT, - // ); + // initVisualKeyboardKey(0), + // initVisualKeyboardKey(1), + // initVisualKeyboardKey(2), + // ], + // undefined, + // BUILDER_KVK_HEADER_FLAGS.kvkhNone, + // null, + // DEFAULT_KVK_FONT, + // DEFAULT_KVK_FONT, + // undefined, + // ); // const writer = new KvkFileWriter; // const binary: BUILDER_KVK_FILE = writer['build'](vk); // checkBuilderKvkFile(binary, vk); // }); // it('can handle a null ansiFont name', () => { // const vk = initVisualKeyboard([ - // initVisualKeyboardKey(0), - // initVisualKeyboardKey(1), - // initVisualKeyboardKey(2), - // ], - // BUILDER_KVK_HEADER_FLAGS.kvkhNone, - // "associatedKeyboard", - // { name: null, size: -12 }, - // DEFAULT_KVK_FONT, - // ); + // initVisualKeyboardKey(0), + // initVisualKeyboardKey(1), + // initVisualKeyboardKey(2), + // ], + // undefined, + // BUILDER_KVK_HEADER_FLAGS.kvkhNone, + // "associatedKeyboard", + // { name: null, size: -12 }, + // DEFAULT_KVK_FONT, + // undefined, + // ); // const writer = new KvkFileWriter; // const binary: BUILDER_KVK_FILE = writer['build'](vk); // checkBuilderKvkFile(binary, vk); // }); // it('can handle a null unicodeFont name', () => { // const vk = initVisualKeyboard([ - // initVisualKeyboardKey(0), - // initVisualKeyboardKey(1), - // initVisualKeyboardKey(2), - // ], - // BUILDER_KVK_HEADER_FLAGS.kvkhNone, - // "associatedKeyboard", - // DEFAULT_KVK_FONT, - // { name: null, size: -12 }, - // ); + // initVisualKeyboardKey(0), + // initVisualKeyboardKey(1), + // initVisualKeyboardKey(2), + // ], + // undefined, + // BUILDER_KVK_HEADER_FLAGS.kvkhNone, + // "associatedKeyboard", + // DEFAULT_KVK_FONT, + // { name: null, size: -12 }, + // undefined, + // ); // const writer = new KvkFileWriter; // const binary: BUILDER_KVK_FILE = writer['build'](vk); // checkBuilderKvkFile(binary, vk); // }); + it('can handle a null vkey', () => { + const vk = initVisualKeyboard([ + initVisualKeyboardKey( + null, + BUILDER_KVK_KEY_FLAGS.kvkkBitmap, + BUILDER_KVK_SHIFT_STATE.KVKS_NORMAL, + "text", + null, + ), + initVisualKeyboardKey(1), + initVisualKeyboardKey(2), + ]); + const writer = new KvkFileWriter; + const binary: BUILDER_KVK_FILE = writer['build'](vk); + checkBuilderKvkFile(binary, vk); + }); + it('can handle a null key flags', () => { + const vk = initVisualKeyboard([ + initVisualKeyboardKey( + 0, + null, + BUILDER_KVK_SHIFT_STATE.KVKS_NORMAL, + "text", + null, + ), + initVisualKeyboardKey(1), + initVisualKeyboardKey(2), + ]); + const writer = new KvkFileWriter; + const binary: BUILDER_KVK_FILE = writer['build'](vk); + checkBuilderKvkFile(binary, vk); + }); + it('can handle a null key shift', () => { + const vk = initVisualKeyboard([ + initVisualKeyboardKey( + 0, + BUILDER_KVK_KEY_FLAGS.kvkkBitmap, + null, + "text", + null, + ), + initVisualKeyboardKey(1), + initVisualKeyboardKey(2), + ]); + const writer = new KvkFileWriter; + const binary: BUILDER_KVK_FILE = writer['build'](vk); + checkBuilderKvkFile(binary, vk); + }); it('can handle a null key text', () => { const vk = initVisualKeyboard([ initVisualKeyboardKey( @@ -163,33 +234,35 @@ describe('Test of KVK-File-Writer', () => { function initVisualKeyboard( vkks: VisualKeyboardKey[], + version: number = undefined, flags: BUILDER_KVK_HEADER_FLAGS = BUILDER_KVK_HEADER_FLAGS.kvkhNone, associatedKeyboard: string = "associatedKeyboard", ansiFont: VisualKeyboardFont = DEFAULT_KVK_FONT, unicodeFont: VisualKeyboardFont = DEFAULT_KVK_FONT, + underlyingLayout: string = undefined, ): VisualKeyboard { const vkh = { - // version?: number, + version: version, flags: flags, associatedKeyboard: associatedKeyboard, ansiFont: ansiFont, unicodeFont: unicodeFont, - // underlyingLayout?: string, + underlyingLayout: underlyingLayout, }; return { header: vkh, keys: vkks }; }; function initVisualKeyboardKey( - index: number, + vkey: number, flags: BUILDER_KVK_KEY_FLAGS = BUILDER_KVK_KEY_FLAGS.kvkkBitmap, shift: BUILDER_KVK_SHIFT_STATE = BUILDER_KVK_SHIFT_STATE.KVKS_NORMAL, text: string = "text", bitmap: number[] = null, ): VisualKeyboardKey { const vkk: VisualKeyboardKey = { + vkey: vkey, flags: flags, shift: shift, - vkey: index, text: text, bitmap: bitmap ? new Uint8Array(bitmap) : null, }; From 5f66cf4e6afb10fcda7acb10ba7edb9f4f03670f Mon Sep 17 00:00:00 2001 From: "Dr Mark C. Sinclair" Date: Mon, 9 Dec 2024 10:40:15 +0000 Subject: [PATCH 18/20] chore(common/web): add local variables to test cases for clarity --- .../types/tests/kvk/kvk-file-writer.tests.ts | 27 ++++++++++++------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/common/web/types/tests/kvk/kvk-file-writer.tests.ts b/common/web/types/tests/kvk/kvk-file-writer.tests.ts index cd386016c9c..955d21c53a9 100644 --- a/common/web/types/tests/kvk/kvk-file-writer.tests.ts +++ b/common/web/types/tests/kvk/kvk-file-writer.tests.ts @@ -51,12 +51,13 @@ describe('Test of KVK-File-Writer', () => { checkBuilderKvkFile(binary, vk); }); it('does not take account of the VisualKeyboard version', () => { + const vk_version = (BUILDER_KVK_HEADER_VERSION + 0x0100); const vk = initVisualKeyboard([ initVisualKeyboardKey(0), initVisualKeyboardKey(1), initVisualKeyboardKey(2), ], - (BUILDER_KVK_HEADER_VERSION + 0x0100), + vk_version, BUILDER_KVK_HEADER_FLAGS.kvkhNone, "associatedKeyboard", DEFAULT_KVK_FONT, @@ -68,6 +69,7 @@ describe('Test of KVK-File-Writer', () => { checkBuilderKvkFile(binary, vk); }); // it('can handle a null associatedKeyboard', () => { + // const vk_associatedKeyboard: string = null; // const vk = initVisualKeyboard([ // initVisualKeyboardKey(0), // initVisualKeyboardKey(1), @@ -75,7 +77,7 @@ describe('Test of KVK-File-Writer', () => { // ], // undefined, // BUILDER_KVK_HEADER_FLAGS.kvkhNone, - // null, + // vk_associatedKeyboard, // DEFAULT_KVK_FONT, // DEFAULT_KVK_FONT, // undefined, @@ -85,6 +87,7 @@ describe('Test of KVK-File-Writer', () => { // checkBuilderKvkFile(binary, vk); // }); // it('can handle a null ansiFont name', () => { + // const vk_ansiFont_name: string = null; // const vk = initVisualKeyboard([ // initVisualKeyboardKey(0), // initVisualKeyboardKey(1), @@ -93,7 +96,7 @@ describe('Test of KVK-File-Writer', () => { // undefined, // BUILDER_KVK_HEADER_FLAGS.kvkhNone, // "associatedKeyboard", - // { name: null, size: -12 }, + // { name: vk_ansiFont_name, size: -12 }, // DEFAULT_KVK_FONT, // undefined, // ); @@ -102,6 +105,7 @@ describe('Test of KVK-File-Writer', () => { // checkBuilderKvkFile(binary, vk); // }); // it('can handle a null unicodeFont name', () => { + // const vk_unicodeFont_name: string = null; // const vk = initVisualKeyboard([ // initVisualKeyboardKey(0), // initVisualKeyboardKey(1), @@ -111,7 +115,7 @@ describe('Test of KVK-File-Writer', () => { // BUILDER_KVK_HEADER_FLAGS.kvkhNone, // "associatedKeyboard", // DEFAULT_KVK_FONT, - // { name: null, size: -12 }, + // { name: vk_unicodeFont_name, size: -12 }, // undefined, // ); // const writer = new KvkFileWriter; @@ -119,9 +123,10 @@ describe('Test of KVK-File-Writer', () => { // checkBuilderKvkFile(binary, vk); // }); it('can handle a null vkey', () => { + const vkk_vkey: number = null; const vk = initVisualKeyboard([ initVisualKeyboardKey( - null, + vkk_vkey, BUILDER_KVK_KEY_FLAGS.kvkkBitmap, BUILDER_KVK_SHIFT_STATE.KVKS_NORMAL, "text", @@ -135,10 +140,11 @@ describe('Test of KVK-File-Writer', () => { checkBuilderKvkFile(binary, vk); }); it('can handle a null key flags', () => { + const vkk_flags: BUILDER_KVK_KEY_FLAGS = null; const vk = initVisualKeyboard([ initVisualKeyboardKey( 0, - null, + vkk_flags, BUILDER_KVK_SHIFT_STATE.KVKS_NORMAL, "text", null, @@ -151,11 +157,12 @@ describe('Test of KVK-File-Writer', () => { checkBuilderKvkFile(binary, vk); }); it('can handle a null key shift', () => { + const vkk_shift: BUILDER_KVK_SHIFT_STATE = null; const vk = initVisualKeyboard([ initVisualKeyboardKey( 0, BUILDER_KVK_KEY_FLAGS.kvkkBitmap, - null, + vkk_shift, "text", null, ), @@ -167,12 +174,13 @@ describe('Test of KVK-File-Writer', () => { checkBuilderKvkFile(binary, vk); }); it('can handle a null key text', () => { + const vkk_text: string = null; const vk = initVisualKeyboard([ initVisualKeyboardKey( 0, BUILDER_KVK_KEY_FLAGS.kvkkBitmap, BUILDER_KVK_SHIFT_STATE.KVKS_NORMAL, - null, + vkk_text, null, ), initVisualKeyboardKey(1), @@ -183,13 +191,14 @@ describe('Test of KVK-File-Writer', () => { checkBuilderKvkFile(binary, vk); }); it('can handle a non-null key bitmap', () => { + const vkk_bitmap: number[] = [0]; const vk = initVisualKeyboard([ initVisualKeyboardKey( 0, BUILDER_KVK_KEY_FLAGS.kvkkBitmap, BUILDER_KVK_SHIFT_STATE.KVKS_NORMAL, "text", - [0], + vkk_bitmap, ), initVisualKeyboardKey(1), initVisualKeyboardKey(2), From 2a7ff5c60f08e5dcf234d5977e8c4b550792e664 Mon Sep 17 00:00:00 2001 From: "Dr Mark C. Sinclair" <52877423+markcsinclair@users.noreply.github.com> Date: Tue, 10 Dec 2024 10:33:02 +0000 Subject: [PATCH 19/20] Update common/web/types/tests/kvk/kvk-file-writer.tests.ts Co-authored-by: Marc Durdin --- common/web/types/tests/kvk/kvk-file-writer.tests.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/common/web/types/tests/kvk/kvk-file-writer.tests.ts b/common/web/types/tests/kvk/kvk-file-writer.tests.ts index 955d21c53a9..89778ffa6b9 100644 --- a/common/web/types/tests/kvk/kvk-file-writer.tests.ts +++ b/common/web/types/tests/kvk/kvk-file-writer.tests.ts @@ -269,10 +269,10 @@ function initVisualKeyboardKey( bitmap: number[] = null, ): VisualKeyboardKey { const vkk: VisualKeyboardKey = { - vkey: vkey, - flags: flags, - shift: shift, - text: text, + vkey, + flags, + shift, + text, bitmap: bitmap ? new Uint8Array(bitmap) : null, }; return vkk; From 255e1f5c88a01cefecbbc7bb821264629144ba6f Mon Sep 17 00:00:00 2001 From: "Dr Mark C. Sinclair" Date: Tue, 10 Dec 2024 10:43:57 +0000 Subject: [PATCH 20/20] chore(common/web): replace three commented-out test cases with it.skip() --- .../types/tests/kvk/kvk-file-writer.tests.ts | 108 +++++++++--------- 1 file changed, 54 insertions(+), 54 deletions(-) diff --git a/common/web/types/tests/kvk/kvk-file-writer.tests.ts b/common/web/types/tests/kvk/kvk-file-writer.tests.ts index 89778ffa6b9..b579446cf62 100644 --- a/common/web/types/tests/kvk/kvk-file-writer.tests.ts +++ b/common/web/types/tests/kvk/kvk-file-writer.tests.ts @@ -68,60 +68,60 @@ describe('Test of KVK-File-Writer', () => { const binary: BUILDER_KVK_FILE = writer['build'](vk); checkBuilderKvkFile(binary, vk); }); - // it('can handle a null associatedKeyboard', () => { - // const vk_associatedKeyboard: string = null; - // const vk = initVisualKeyboard([ - // initVisualKeyboardKey(0), - // initVisualKeyboardKey(1), - // initVisualKeyboardKey(2), - // ], - // undefined, - // BUILDER_KVK_HEADER_FLAGS.kvkhNone, - // vk_associatedKeyboard, - // DEFAULT_KVK_FONT, - // DEFAULT_KVK_FONT, - // undefined, - // ); - // const writer = new KvkFileWriter; - // const binary: BUILDER_KVK_FILE = writer['build'](vk); - // checkBuilderKvkFile(binary, vk); - // }); - // it('can handle a null ansiFont name', () => { - // const vk_ansiFont_name: string = null; - // const vk = initVisualKeyboard([ - // initVisualKeyboardKey(0), - // initVisualKeyboardKey(1), - // initVisualKeyboardKey(2), - // ], - // undefined, - // BUILDER_KVK_HEADER_FLAGS.kvkhNone, - // "associatedKeyboard", - // { name: vk_ansiFont_name, size: -12 }, - // DEFAULT_KVK_FONT, - // undefined, - // ); - // const writer = new KvkFileWriter; - // const binary: BUILDER_KVK_FILE = writer['build'](vk); - // checkBuilderKvkFile(binary, vk); - // }); - // it('can handle a null unicodeFont name', () => { - // const vk_unicodeFont_name: string = null; - // const vk = initVisualKeyboard([ - // initVisualKeyboardKey(0), - // initVisualKeyboardKey(1), - // initVisualKeyboardKey(2), - // ], - // undefined, - // BUILDER_KVK_HEADER_FLAGS.kvkhNone, - // "associatedKeyboard", - // DEFAULT_KVK_FONT, - // { name: vk_unicodeFont_name, size: -12 }, - // undefined, - // ); - // const writer = new KvkFileWriter; - // const binary: BUILDER_KVK_FILE = writer['build'](vk); - // checkBuilderKvkFile(binary, vk); - // }); + it.skip('can handle a null associatedKeyboard', () => { + const vk_associatedKeyboard: string = null; + const vk = initVisualKeyboard([ + initVisualKeyboardKey(0), + initVisualKeyboardKey(1), + initVisualKeyboardKey(2), + ], + undefined, + BUILDER_KVK_HEADER_FLAGS.kvkhNone, + vk_associatedKeyboard, + DEFAULT_KVK_FONT, + DEFAULT_KVK_FONT, + undefined, + ); + const writer = new KvkFileWriter; + const binary: BUILDER_KVK_FILE = writer['build'](vk); + checkBuilderKvkFile(binary, vk); + }); + it.skip('can handle a null ansiFont name', () => { + const vk_ansiFont_name: string = null; + const vk = initVisualKeyboard([ + initVisualKeyboardKey(0), + initVisualKeyboardKey(1), + initVisualKeyboardKey(2), + ], + undefined, + BUILDER_KVK_HEADER_FLAGS.kvkhNone, + "associatedKeyboard", + { name: vk_ansiFont_name, size: -12 }, + DEFAULT_KVK_FONT, + undefined, + ); + const writer = new KvkFileWriter; + const binary: BUILDER_KVK_FILE = writer['build'](vk); + checkBuilderKvkFile(binary, vk); + }); + it.skip('can handle a null unicodeFont name', () => { + const vk_unicodeFont_name: string = null; + const vk = initVisualKeyboard([ + initVisualKeyboardKey(0), + initVisualKeyboardKey(1), + initVisualKeyboardKey(2), + ], + undefined, + BUILDER_KVK_HEADER_FLAGS.kvkhNone, + "associatedKeyboard", + DEFAULT_KVK_FONT, + { name: vk_unicodeFont_name, size: -12 }, + undefined, + ); + const writer = new KvkFileWriter; + const binary: BUILDER_KVK_FILE = writer['build'](vk); + checkBuilderKvkFile(binary, vk); + }); it('can handle a null vkey', () => { const vkk_vkey: number = null; const vk = initVisualKeyboard([