From 986c0ed4869eeb013e51958ef9f893692674bcde Mon Sep 17 00:00:00 2001 From: "Dr Mark C. Sinclair" Date: Mon, 9 Dec 2024 10:55:37 +0000 Subject: [PATCH 1/2] fix(common/web): improve null handling for three variables and correct initialisation of four --- common/web/types/src/kvk/kvk-file-writer.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/common/web/types/src/kvk/kvk-file-writer.ts b/common/web/types/src/kvk/kvk-file-writer.ts index a9845c0d853..6b7d2831564 100644 --- a/common/web/types/src/kvk/kvk-file-writer.ts +++ b/common/web/types/src/kvk/kvk-file-writer.ts @@ -29,33 +29,33 @@ export default class KvkFileWriter { header: { identifier: BUILDER_KVK_HEADER_IDENTIFIER, version: BUILDER_KVK_HEADER_VERSION, - associatedKeyboard: {len:0,str:''}, + associatedKeyboard: {len:1,str:''}, flags: source.header.flags, ansiFont:{ color: VISUAL_KEYBOARD_TEXT_COLOR, size: source.header.ansiFont.size, - name: {len:0,str:''} + name: {len:1,str:''} }, unicodeFont:{ color: VISUAL_KEYBOARD_TEXT_COLOR, size: source.header.unicodeFont.size, - name: {len:0,str:''} + name: {len:1,str:''} }, }, keyCount: source.keys.length, keys:[] }; - this.setString(binary.header.associatedKeyboard, source.header.associatedKeyboard); - this.setString(binary.header.ansiFont.name, source.header.ansiFont.name); - this.setString(binary.header.unicodeFont.name, source.header.unicodeFont.name); + this.setString(binary.header.associatedKeyboard, source.header.associatedKeyboard || ''); + this.setString(binary.header.ansiFont.name, source.header.ansiFont.name || ''); + this.setString(binary.header.unicodeFont.name, source.header.unicodeFont.name || ''); for(let sourceKey of source.keys) { const binaryKey: BUILDER_KVK_KEY = { flags: sourceKey.flags, vkey: sourceKey.vkey, shift: sourceKey.shift, - text: { len: 0, str: '' }, + text: { len: 1, str: '' }, bitmapSize: sourceKey.bitmap ? sourceKey.bitmap.byteLength : 0, bitmapData: sourceKey.bitmap ? Array.from(sourceKey.bitmap) : [] }; From 4c48119576707832eaa8f81df8d844a4b7081171 Mon Sep 17 00:00:00 2001 From: "Dr Mark C. Sinclair" Date: Mon, 9 Dec 2024 10:59:29 +0000 Subject: [PATCH 2/2] chore(common/web): un comment out three test cases for null strings --- .../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 955d21c53a9..264bb60c9b6 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('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('can handle a null vkey', () => { const vkk_vkey: number = null; const vk = initVisualKeyboard([