diff options
author | Angelos Mouzakitis <a.mouzakitis@virtualopensystems.com> | 2023-10-10 14:33:42 +0000 |
---|---|---|
committer | Angelos Mouzakitis <a.mouzakitis@virtualopensystems.com> | 2023-10-10 14:33:42 +0000 |
commit | af1a266670d040d2f4083ff309d732d648afba2a (patch) | |
tree | 2fc46203448ddcc6f81546d379abfaeb323575e9 /ui/keycodemapdb/tests | |
parent | e02cda008591317b1625707ff8e115a4841aa889 (diff) |
Change-Id: Iaf8d18082d3991dec7c0ebbea540f092188eb4ec
Diffstat (limited to 'ui/keycodemapdb/tests')
-rw-r--r-- | ui/keycodemapdb/tests/.gitignore | 11 | ||||
-rw-r--r-- | ui/keycodemapdb/tests/Makefile | 171 | ||||
-rwxr-xr-x | ui/keycodemapdb/tests/javascript | 53 | ||||
-rwxr-xr-x | ui/keycodemapdb/tests/python2 | 3 | ||||
-rwxr-xr-x | ui/keycodemapdb/tests/python3 | 3 | ||||
-rwxr-xr-x | ui/keycodemapdb/tests/rust | 5 | ||||
-rw-r--r-- | ui/keycodemapdb/tests/rust-test/Cargo.toml | 10 | ||||
-rw-r--r-- | ui/keycodemapdb/tests/rust-test/src/main.rs | 28 | ||||
-rw-r--r-- | ui/keycodemapdb/tests/stdc++.cc | 40 | ||||
-rw-r--r-- | ui/keycodemapdb/tests/stdc.c | 64 | ||||
-rw-r--r-- | ui/keycodemapdb/tests/test.py | 30 |
11 files changed, 418 insertions, 0 deletions
diff --git a/ui/keycodemapdb/tests/.gitignore b/ui/keycodemapdb/tests/.gitignore new file mode 100644 index 000000000..05623054a --- /dev/null +++ b/ui/keycodemapdb/tests/.gitignore @@ -0,0 +1,11 @@ +osx2win32.* +osx2win32_name.* +osx2xkb.* +osx2xkb_name.* +html2win32.* +html2win32_name.* +osx.* +osx_name.* +stdc +stdc++ +node_modules/ diff --git a/ui/keycodemapdb/tests/Makefile b/ui/keycodemapdb/tests/Makefile new file mode 100644 index 000000000..3ac7a21ac --- /dev/null +++ b/ui/keycodemapdb/tests/Makefile @@ -0,0 +1,171 @@ +TESTS := stdc stdc++ python2 python3 javascript rust + +check: $(TESTS) + @set -e; for fn in $(TESTS); do \ + ./$$fn; \ + echo $$fn: OK; \ + done + @echo Done. + +GEN := ../tools/keymap-gen +DATA := ../data/keymaps.csv +SOURCES := $(GEN) $(DATA) + +.DELETE_ON_ERROR: + +stdc: stdc.c osx2win32.h osx2win32.c osx2win32_name.h osx2win32_name.c \ + osx2xkb.h osx2xkb.c osx2xkb_name.h osx2xkb_name.c \ + html2win32.h html2win32.c html2win32_name.h html2win32_name.c \ + osx.h osx.c osx_name.h osx_name.c + $(CC) -Wall -o $@ $(filter %.c, $^) +osx2win32.c: $(SOURCES) + $(GEN) code-map --lang stdc $(DATA) osx win32 > $@ +osx2win32.h: $(SOURCES) + $(GEN) code-map --lang stdc-header $(DATA) osx win32 > $@ +osx2win32_name.c: $(SOURCES) + $(GEN) name-map --lang stdc $(DATA) osx win32 > $@ +osx2win32_name.h: $(SOURCES) + $(GEN) name-map --lang stdc-header $(DATA) osx win32 > $@ +osx2xkb.c: $(SOURCES) + $(GEN) code-map --lang stdc $(DATA) osx xkb > $@ +osx2xkb.h: $(SOURCES) + $(GEN) code-map --lang stdc-header $(DATA) osx xkb > $@ +osx2xkb_name.c: $(SOURCES) + $(GEN) name-map --lang stdc $(DATA) osx xkb > $@ +osx2xkb_name.h: $(SOURCES) + $(GEN) name-map --lang stdc-header $(DATA) osx xkb > $@ +html2win32.c: $(SOURCES) + $(GEN) code-map --lang stdc $(DATA) html win32 > $@ +html2win32.h: $(SOURCES) + $(GEN) code-map --lang stdc-header $(DATA) html win32 > $@ +html2win32_name.c: $(SOURCES) + $(GEN) name-map --lang stdc $(DATA) html win32 > $@ +html2win32_name.h: $(SOURCES) + $(GEN) name-map --lang stdc-header $(DATA) html win32 > $@ +osx.c: $(SOURCES) + $(GEN) code-table --lang stdc $(DATA) osx > $@ +osx.h: $(SOURCES) + $(GEN) code-table --lang stdc-header $(DATA) osx > $@ +osx_name.c: $(SOURCES) + $(GEN) name-table --lang stdc $(DATA) osx > $@ +osx_name.h: $(SOURCES) + $(GEN) name-table --lang stdc-header $(DATA) osx > $@ + +stdc++: stdc++.cc osx2win32.hh osx2win32.cc osx2win32_name.hh osx2win32_name.cc \ + osx2xkb.hh osx2xkb.cc osx2xkb_name.hh osx2xkb_name.cc \ + html2win32.hh html2win32.cc html2win32_name.hh html2win32_name.cc \ + osx.hh osx.cc osx_name.hh osx_name.cc + $(CXX) -Wall -std=c++11 -o $@ $(filter %.cc, $^) +osx2win32.cc: $(SOURCES) + $(GEN) code-map --lang stdc++ $(DATA) osx win32 > $@ +osx2win32.hh: $(SOURCES) + $(GEN) code-map --lang stdc++-header $(DATA) osx win32 > $@ +osx2win32_name.cc: $(SOURCES) + $(GEN) name-map --lang stdc++ $(DATA) osx win32 > $@ +osx2win32_name.hh: $(SOURCES) + $(GEN) name-map --lang stdc++-header $(DATA) osx win32 > $@ +osx2xkb.cc: $(SOURCES) + $(GEN) code-map --lang stdc++ $(DATA) osx xkb > $@ +osx2xkb.hh: $(SOURCES) + $(GEN) code-map --lang stdc++-header $(DATA) osx xkb > $@ +osx2xkb_name.cc: $(SOURCES) + $(GEN) name-map --lang stdc++ $(DATA) osx xkb > $@ +osx2xkb_name.hh: $(SOURCES) + $(GEN) name-map --lang stdc++-header $(DATA) osx xkb > $@ +html2win32.cc: $(SOURCES) + $(GEN) code-map --lang stdc++ $(DATA) html win32 > $@ +html2win32.hh: $(SOURCES) + $(GEN) code-map --lang stdc++-header $(DATA) html win32 > $@ +html2win32_name.cc: $(SOURCES) + $(GEN) name-map --lang stdc++ $(DATA) html win32 > $@ +html2win32_name.hh: $(SOURCES) + $(GEN) name-map --lang stdc++-header $(DATA) html win32 > $@ +osx.cc: $(SOURCES) + $(GEN) code-table --lang stdc++ $(DATA) osx > $@ +osx.hh: $(SOURCES) + $(GEN) code-table --lang stdc++-header $(DATA) osx > $@ +osx_name.cc: $(SOURCES) + $(GEN) name-table --lang stdc++ $(DATA) osx > $@ +osx_name.hh: $(SOURCES) + $(GEN) name-table --lang stdc++-header $(DATA) osx > $@ + +python2: osx2win32.py osx2win32_name.py \ + osx2xkb.py osx2xkb_name.py \ + html2win32.py html2win32_name.py \ + osx.py osx_name.py +osx2win32.py: $(SOURCES) + $(GEN) code-map --lang python2 $(DATA) osx win32 > $@ +osx2win32_name.py: $(SOURCES) + $(GEN) name-map --lang python2 $(DATA) osx win32 > $@ +osx2xkb.py: $(SOURCES) + $(GEN) code-map --lang python2 $(DATA) osx xkb > $@ +osx2xkb_name.py: $(SOURCES) + $(GEN) name-map --lang python2 $(DATA) osx xkb > $@ +html2win32.py: $(SOURCES) + $(GEN) code-map --lang python2 $(DATA) html win32 > $@ +html2win32_name.py: $(SOURCES) + $(GEN) name-map --lang python2 $(DATA) html win32 > $@ +osx.py: $(SOURCES) + $(GEN) code-table --lang python2 $(DATA) osx > $@ +osx_name.py: $(SOURCES) + $(GEN) name-table --lang python2 $(DATA) osx > $@ + +javascript: node_modules/babel-core \ + node_modules/babel-plugin-transform-es2015-modules-commonjs \ + osx2win32.js osx2win32_name.js \ + osx2xkb.js osx2xkb_name.js \ + html2win32.js html2win32_name.js \ + osx.js osx_name.js +node_modules/babel-core: + npm install babel-core +node_modules/babel-plugin-transform-es2015-modules-commonjs: + npm install babel-plugin-transform-es2015-modules-commonjs +osx2win32.js: $(SOURCES) + $(GEN) code-map --lang js $(DATA) osx win32 > $@ +osx2win32_name.js: $(SOURCES) + $(GEN) name-map --lang js $(DATA) osx win32 > $@ +osx2xkb.js: $(SOURCES) + $(GEN) code-map --lang js $(DATA) osx xkb > $@ +osx2xkb_name.js: $(SOURCES) + $(GEN) name-map --lang js $(DATA) osx xkb > $@ +html2win32.js: $(SOURCES) + $(GEN) code-map --lang js $(DATA) html win32 > $@ +html2win32_name.js: $(SOURCES) + $(GEN) name-map --lang js $(DATA) html win32 > $@ +osx.js: $(SOURCES) + $(GEN) code-table --lang js $(DATA) osx > $@ +osx_name.js: $(SOURCES) + $(GEN) name-table --lang js $(DATA) osx > $@ + +rust: osx2win32.rs osx2win32_name.rs \ + osx2xkb.rs osx2xkb_name.rs \ + html2win32.rs html2win32_name.rs \ + osx.rs osx_name.rs +osx2win32.rs: $(SOURCES) + $(GEN) code-map --lang rust $(DATA) osx win32 > $@ +osx2win32_name.rs: $(SOURCES) + $(GEN) name-map --lang rust $(DATA) osx win32 > $@ +osx2xkb.rs: $(SOURCES) + $(GEN) code-map --lang rust $(DATA) osx xkb > $@ +osx2xkb_name.rs: $(SOURCES) + $(GEN) name-map --lang rust $(DATA) osx xkb > $@ +html2win32.rs: $(SOURCES) + $(GEN) code-map --lang rust $(DATA) html win32 > $@ +html2win32_name.rs: $(SOURCES) + $(GEN) name-map --lang rust $(DATA) html win32 > $@ +osx.rs: $(SOURCES) + $(GEN) code-table --lang rust $(DATA) osx > $@ +osx_name.rs: $(SOURCES) + $(GEN) name-table --lang rust $(DATA) osx > $@ + +clean: + rm -rf node_modules + rm -f osx2win32.* + rm -f osx2win32_name.* + rm -f osx2xkb.* + rm -f osx2xkb_name.* + rm -f html2win32.* + rm -f html2win32_name.* + rm -f osx.* + rm -f osx_name.* + rm -f stdc stdc++ diff --git a/ui/keycodemapdb/tests/javascript b/ui/keycodemapdb/tests/javascript new file mode 100755 index 000000000..5179db2ce --- /dev/null +++ b/ui/keycodemapdb/tests/javascript @@ -0,0 +1,53 @@ +#!/usr/bin/env node +/* + * Keycode Map Generator JavaScript Tests + * + * Copyright 2017 Pierre Ossman for Cendio AB + * + * This file is dual license under the terms of the GPLv2 or later + * and 3-clause BSD licenses. + */ + +"use strict"; + +var assert = require('assert'); +var babel = require('babel-core'); +var fs = require('fs'); + +function include(fn) { + var options = { + plugins: ["transform-es2015-modules-commonjs"] + }; + + var code = babel.transformFileSync(fn, options).code; + fs.writeFileSync("." + fn + "_nodejs.js", code); + var imp = require("./." + fn + "_nodejs.js"); + fs.unlinkSync("./." + fn + "_nodejs.js"); + + return imp +} + +var code_map_osx_to_win32 = include("osx2win32.js").default; +var name_map_osx_to_win32 = include("osx2win32_name.js").default; + +var code_map_osx_to_xkb = include("osx2xkb.js").default; +var name_map_osx_to_xkb = include("osx2xkb_name.js").default; + +var code_map_html_to_win32 = include("html2win32.js").default; +var name_map_html_to_win32 = include("html2win32_name.js").default; + +var code_table_osx = include("osx.js").default; +var name_table_osx = include("osx_name.js").default; + +assert.equal(code_map_osx_to_win32[0x1d], 0x30); +assert.equal(name_map_osx_to_win32[0x1d], "VK_0"); + +assert.equal(code_map_osx_to_xkb[0x1d], "AE10"); +assert.equal(name_map_osx_to_xkb[0x1d], "AE10"); + +assert.equal(code_map_html_to_win32["ControlLeft"], 0x11); +assert.equal(name_map_html_to_win32["ControlLeft"], "VK_CONTROL"); + +assert.equal(code_table_osx[0x1d], 0x3b); +assert.equal(name_table_osx[0x1d], "Control"); + diff --git a/ui/keycodemapdb/tests/python2 b/ui/keycodemapdb/tests/python2 new file mode 100755 index 000000000..28a5b0346 --- /dev/null +++ b/ui/keycodemapdb/tests/python2 @@ -0,0 +1,3 @@ +#!/bin/sh + +python ./test.py diff --git a/ui/keycodemapdb/tests/python3 b/ui/keycodemapdb/tests/python3 new file mode 100755 index 000000000..ded1f6806 --- /dev/null +++ b/ui/keycodemapdb/tests/python3 @@ -0,0 +1,3 @@ +#!/bin/sh + +python3 ./test.py diff --git a/ui/keycodemapdb/tests/rust b/ui/keycodemapdb/tests/rust new file mode 100755 index 000000000..0e133b121 --- /dev/null +++ b/ui/keycodemapdb/tests/rust @@ -0,0 +1,5 @@ +#!/bin/sh + +cd rust-test +cargo test +cargo clippy diff --git a/ui/keycodemapdb/tests/rust-test/Cargo.toml b/ui/keycodemapdb/tests/rust-test/Cargo.toml new file mode 100644 index 000000000..832ac377e --- /dev/null +++ b/ui/keycodemapdb/tests/rust-test/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "rust-test" +version = "0.1.0" +authors = ["Marc-André Lureau <marcandre.lureau@redhat.com>"] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +phf = { version = "0.8", features = ["macros"] } diff --git a/ui/keycodemapdb/tests/rust-test/src/main.rs b/ui/keycodemapdb/tests/rust-test/src/main.rs new file mode 100644 index 000000000..ba165d03a --- /dev/null +++ b/ui/keycodemapdb/tests/rust-test/src/main.rs @@ -0,0 +1,28 @@ +include!("../../html2win32_name.rs"); +include!("../../html2win32.rs"); +include!("../../osx2win32_name.rs"); +include!("../../osx2win32.rs"); +include!("../../osx2xkb_name.rs"); +include!("../../osx2xkb.rs"); +include!("../../osx_name.rs"); +include!("../../osx.rs"); + +fn main() { + assert_eq!(CODE_MAP_OSX_TO_WIN32[0x1d], 0x30); + assert_eq!(NAME_MAP_OSX_TO_WIN32[0x1d], "VK_0"); + + assert_eq!(CODE_MAP_OSX_TO_XKB[0x1d], "AE10"); + assert_eq!(NAME_MAP_OSX_TO_XKB[0x1d], "AE10"); + + assert_eq!(CODE_MAP_HTML_TO_WIN32["ControlLeft"], 0x11); + assert_eq!(NAME_MAP_HTML_TO_WIN32["ControlLeft"], "VK_CONTROL"); + + assert_eq!(CODE_TABLE_OSX[0x1d], 0x3b); + assert_eq!(NAME_TABLE_OSX[0x1d], "Control"); +} + + +#[test] +fn test() { + main() +} diff --git a/ui/keycodemapdb/tests/stdc++.cc b/ui/keycodemapdb/tests/stdc++.cc new file mode 100644 index 000000000..5e3e8f551 --- /dev/null +++ b/ui/keycodemapdb/tests/stdc++.cc @@ -0,0 +1,40 @@ +/* + * Keycode Map Generator C++ Tests + * + * Copyright 2017 Pierre Ossman for Cendio AB + * + * This file is dual license under the terms of the GPLv2 or later + * and 3-clause BSD licenses. + */ + +#include <assert.h> +#include <string.h> + +#include "osx2win32.hh" +#include "osx2win32_name.hh" + +#include "osx2xkb.hh" +#include "osx2xkb_name.hh" + +#include "html2win32.hh" +#include "html2win32_name.hh" + +#include "osx.hh" +#include "osx_name.hh" + +int main(int argc, char** argv) +{ + assert(code_map_osx_to_win32[0x1d] == 0x30); + assert(strcmp(name_map_osx_to_win32[0x1d], "VK_0") == 0); + + assert(strcmp(code_map_osx_to_xkb[0x1d], "AE10") == 0); + assert(strcmp(name_map_osx_to_xkb[0x1d], "AE10") == 0); + + assert(code_map_html_to_win32.at("ControlLeft") == 0x11); + assert(strcmp(name_map_html_to_win32.at("ControlLeft"), "VK_CONTROL") == 0); + + assert(code_table_osx[0x1d] == 0x3b); + assert(strcmp(name_table_osx[0x1d], "Control") == 0); + + return 0; +} diff --git a/ui/keycodemapdb/tests/stdc.c b/ui/keycodemapdb/tests/stdc.c new file mode 100644 index 000000000..e4946fa53 --- /dev/null +++ b/ui/keycodemapdb/tests/stdc.c @@ -0,0 +1,64 @@ +/* + * Keycode Map Generator C Tests + * + * Copyright 2017 Pierre Ossman for Cendio AB + * + * This file is dual license under the terms of the GPLv2 or later + * and 3-clause BSD licenses. + */ + +#include <assert.h> +#include <string.h> + +#include "osx2win32.h" +#include "osx2win32_name.h" + +#include "osx2xkb.h" +#include "osx2xkb_name.h" + +#include "html2win32.h" +#include "html2win32_name.h" + +#include "osx.h" +#include "osx_name.h" + +#define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0])) + +int main(int argc, char** argv) +{ + unsigned i; + + assert(code_map_osx_to_win32_len == ARRAY_SIZE(code_map_osx_to_win32)); + assert(code_map_osx_to_win32[0x1d] == 0x30); + assert(name_map_osx_to_win32_len == ARRAY_SIZE(name_map_osx_to_win32)); + assert(strcmp(name_map_osx_to_win32[0x1d], "VK_0") == 0); + + assert(code_map_osx_to_xkb_len == ARRAY_SIZE(code_map_osx_to_xkb)); + assert(strcmp(code_map_osx_to_xkb[0x1d], "AE10") == 0); + assert(name_map_osx_to_xkb_len == ARRAY_SIZE(name_map_osx_to_xkb)); + assert(strcmp(name_map_osx_to_xkb[0x1d], "AE10") == 0); + + assert(code_map_html_to_win32_len == ARRAY_SIZE(code_map_html_to_win32)); + for (i = 0;i < code_map_html_to_win32_len;i++) { + if (strcmp(code_map_html_to_win32[i].from, "ControlLeft") == 0) { + assert(code_map_html_to_win32[i].to == 0x11); + break; + } + } + assert(i != code_map_html_to_win32_len); + assert(name_map_html_to_win32_len == ARRAY_SIZE(name_map_html_to_win32)); + for (i = 0;i < name_map_html_to_win32_len;i++) { + if (strcmp(name_map_html_to_win32[i].from, "ControlLeft") == 0) { + assert(strcmp(name_map_html_to_win32[i].to, "VK_CONTROL") == 0); + break; + } + } + assert(i != name_map_html_to_win32_len); + + assert(code_table_osx_len == ARRAY_SIZE(code_table_osx)); + assert(code_table_osx[0x1d] == 0x3b); + assert(name_table_osx_len == ARRAY_SIZE(name_table_osx)); + assert(strcmp(name_table_osx[0x1d], "Control") == 0); + + return 0; +} diff --git a/ui/keycodemapdb/tests/test.py b/ui/keycodemapdb/tests/test.py new file mode 100644 index 000000000..f26514558 --- /dev/null +++ b/ui/keycodemapdb/tests/test.py @@ -0,0 +1,30 @@ +# Keycode Map Generator Python Tests +# +# Copyright 2017 Pierre Ossman for Cendio AB +# +# This file is dual license under the terms of the GPLv2 or later +# and 3-clause BSD licenses. + +import osx2win32 +import osx2win32_name + +import osx2xkb +import osx2xkb_name + +import html2win32 +import html2win32_name + +import osx +import osx_name + +assert osx2win32.code_map_osx_to_win32[0x1d] == 0x30 +assert osx2win32_name.name_map_osx_to_win32[0x1d] == "VK_0" + +assert osx2xkb.code_map_osx_to_xkb[0x1d] == "AE10" +assert osx2xkb_name.name_map_osx_to_xkb[0x1d] == "AE10" + +assert html2win32.code_map_html_to_win32["ControlLeft"] == 0x11 +assert html2win32_name.name_map_html_to_win32["ControlLeft"] == "VK_CONTROL" + +assert osx.code_table_osx[0x1d] == 0x3b; +assert osx_name.name_table_osx[0x1d] == "Control"; |