tests: Verify all bundled layouts
This commit is contained in:
29
examples/test_layout.rs
Normal file
29
examples/test_layout.rs
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
extern crate rs;
|
||||||
|
extern crate xkbcommon;
|
||||||
|
|
||||||
|
use std::env;
|
||||||
|
|
||||||
|
use rs::data::{ load_layout_from_resource, LoadError };
|
||||||
|
|
||||||
|
use xkbcommon::xkb;
|
||||||
|
|
||||||
|
|
||||||
|
fn check_layout(name: &str) {
|
||||||
|
let layout = load_layout_from_resource(name)
|
||||||
|
.and_then(|layout| layout.build().map_err(LoadError::BadKeyMap))
|
||||||
|
.expect("layout broken");
|
||||||
|
|
||||||
|
let context = xkb::Context::new(xkb::CONTEXT_NO_FLAGS);
|
||||||
|
xkb::Keymap::new_from_string(
|
||||||
|
&context,
|
||||||
|
layout.keymap_str
|
||||||
|
.clone()
|
||||||
|
.into_string().expect("Failed to decode keymap string"),
|
||||||
|
xkb::KEYMAP_FORMAT_TEXT_V1,
|
||||||
|
xkb::KEYMAP_COMPILE_NO_FLAGS,
|
||||||
|
).expect("Failed to create keymap");
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() -> () {
|
||||||
|
check_layout(env::args().nth(1).expect("No argument given").as_str());
|
||||||
|
}
|
||||||
@ -53,6 +53,9 @@ summary = [
|
|||||||
]
|
]
|
||||||
message('\n'.join(summary))
|
message('\n'.join(summary))
|
||||||
|
|
||||||
|
cargo = find_program('cargo')
|
||||||
|
cargo_script = find_program('cargo.sh')
|
||||||
|
|
||||||
subdir('data')
|
subdir('data')
|
||||||
subdir('protocols')
|
subdir('protocols')
|
||||||
subdir('eek')
|
subdir('eek')
|
||||||
|
|||||||
10
src/data.rs
10
src/data.rs
@ -48,7 +48,7 @@ pub mod c {
|
|||||||
const FALLBACK_LAYOUT_NAME: &str = "us";
|
const FALLBACK_LAYOUT_NAME: &str = "us";
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
enum LoadError {
|
pub enum LoadError {
|
||||||
BadData(Error),
|
BadData(Error),
|
||||||
MissingResource,
|
MissingResource,
|
||||||
BadResource(serde_yaml::Error),
|
BadResource(serde_yaml::Error),
|
||||||
@ -67,7 +67,7 @@ impl fmt::Display for LoadError {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn load_layout_from_resource(
|
pub fn load_layout_from_resource(
|
||||||
name: &str
|
name: &str
|
||||||
) -> Result<Layout, LoadError> {
|
) -> Result<Layout, LoadError> {
|
||||||
let data = resources::get_keyboard(name)
|
let data = resources::get_keyboard(name)
|
||||||
@ -169,7 +169,7 @@ fn load_layout_with_fallback(
|
|||||||
/// The root element describing an entire keyboard
|
/// The root element describing an entire keyboard
|
||||||
#[derive(Debug, Deserialize, PartialEq)]
|
#[derive(Debug, Deserialize, PartialEq)]
|
||||||
#[serde(deny_unknown_fields)]
|
#[serde(deny_unknown_fields)]
|
||||||
struct Layout {
|
pub struct Layout {
|
||||||
bounds: Bounds,
|
bounds: Bounds,
|
||||||
views: HashMap<String, Vec<ButtonIds>>,
|
views: HashMap<String, Vec<ButtonIds>>,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
@ -223,7 +223,7 @@ struct Outline {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
enum Error {
|
pub enum Error {
|
||||||
Yaml(serde_yaml::Error),
|
Yaml(serde_yaml::Error),
|
||||||
Io(io::Error),
|
Io(io::Error),
|
||||||
}
|
}
|
||||||
@ -248,7 +248,7 @@ impl Layout {
|
|||||||
serde_yaml::from_reader(infile)
|
serde_yaml::from_reader(infile)
|
||||||
.map_err(Error::Yaml)
|
.map_err(Error::Yaml)
|
||||||
}
|
}
|
||||||
fn build(self) -> Result<::layout::Layout, FormattingError> {
|
pub fn build(self) -> Result<::layout::Layout, FormattingError> {
|
||||||
let button_names = self.views.values()
|
let button_names = self.views.values()
|
||||||
.flat_map(|rows| {
|
.flat_map(|rows| {
|
||||||
rows.iter()
|
rows.iter()
|
||||||
|
|||||||
@ -5,7 +5,7 @@ extern crate maplit;
|
|||||||
extern crate serde;
|
extern crate serde;
|
||||||
extern crate xkbcommon;
|
extern crate xkbcommon;
|
||||||
|
|
||||||
mod data;
|
pub mod data;
|
||||||
pub mod float_ord;
|
pub mod float_ord;
|
||||||
pub mod imservice;
|
pub mod imservice;
|
||||||
mod keyboard;
|
mod keyboard;
|
||||||
|
|||||||
@ -55,9 +55,6 @@ deps = [
|
|||||||
# dependency('libxklavier'), # FIXME remove
|
# dependency('libxklavier'), # FIXME remove
|
||||||
]
|
]
|
||||||
|
|
||||||
cargo = find_program('cargo')
|
|
||||||
cargo_script = find_program('../cargo.sh')
|
|
||||||
|
|
||||||
rslibs = custom_target(
|
rslibs = custom_target(
|
||||||
'rslibs',
|
'rslibs',
|
||||||
build_by_default: true,
|
build_by_default: true,
|
||||||
|
|||||||
@ -19,11 +19,10 @@ test_link_args = [
|
|||||||
'-fPIC',
|
'-fPIC',
|
||||||
]
|
]
|
||||||
|
|
||||||
tests = [
|
c_tests = [
|
||||||
'test-keymap-generation'
|
|
||||||
]
|
]
|
||||||
|
|
||||||
foreach name : tests
|
foreach name : c_tests
|
||||||
|
|
||||||
test_sources = [name + '.c']
|
test_sources = [name + '.c']
|
||||||
|
|
||||||
@ -45,4 +44,15 @@ foreach name : tests
|
|||||||
|
|
||||||
endforeach
|
endforeach
|
||||||
|
|
||||||
|
# The layout test is in the examples directory
|
||||||
|
# due to the way Cargo builds executables
|
||||||
|
# and the need to call it manually
|
||||||
|
foreach layout : ['us', 'nb']
|
||||||
|
test(
|
||||||
|
'test_layout_' + layout,
|
||||||
|
cargo_script,
|
||||||
|
args: [meson.source_root(), '', 'run', '--example', 'test_layout', layout]
|
||||||
|
)
|
||||||
|
endforeach
|
||||||
|
|
||||||
endif
|
endif
|
||||||
|
|||||||
@ -1,64 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2010-2011 Daiki Ueno <ueno@unixuser.org>
|
|
||||||
* Copyright (C) 2010-2011 Red Hat, Inc.
|
|
||||||
* Copyright (C) 2019 Purism SPC
|
|
||||||
*
|
|
||||||
* This library is free software; you can redistribute it and/or
|
|
||||||
* modify it under the terms of the GNU Lesser General Public License
|
|
||||||
* as published by the Free Software Foundation; either version 2 of
|
|
||||||
* the License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This library is distributed in the hope that it will be useful, but
|
|
||||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
* Lesser General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public
|
|
||||||
* License along with this library; if not, write to the Free Software
|
|
||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
||||||
* 02110-1301 USA
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* For gdk_x11_display_get_xdisplay(). See main(). */
|
|
||||||
#include <gtk/gtk.h>
|
|
||||||
#include <xkbcommon/xkbcommon.h>
|
|
||||||
|
|
||||||
#include "config.h"
|
|
||||||
|
|
||||||
#include "eek/eek-xml-layout.h"
|
|
||||||
#include "eek/eek-keyboard.h"
|
|
||||||
|
|
||||||
#include "src/layout.h"
|
|
||||||
|
|
||||||
static void
|
|
||||||
test_check_xkb (void)
|
|
||||||
{
|
|
||||||
LevelKeyboard *keyboard = eek_xml_layout_real_create_keyboard("us", NULL);
|
|
||||||
const gchar *keymap_str = squeek_layout_get_keymap(keyboard->layout);
|
|
||||||
|
|
||||||
struct xkb_context *context = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
|
|
||||||
if (!context) {
|
|
||||||
g_error("No context created");
|
|
||||||
}
|
|
||||||
|
|
||||||
struct xkb_keymap *keymap = xkb_keymap_new_from_string(context, keymap_str,
|
|
||||||
XKB_KEYMAP_FORMAT_TEXT_V1, XKB_KEYMAP_COMPILE_NO_FLAGS);
|
|
||||||
|
|
||||||
xkb_context_unref(context);
|
|
||||||
if (!keymap) {
|
|
||||||
printf("%s", keymap_str);
|
|
||||||
g_error("Bad keymap");
|
|
||||||
}
|
|
||||||
|
|
||||||
level_keyboard_free(keyboard);
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
main (int argc, char **argv)
|
|
||||||
{
|
|
||||||
g_test_init (&argc, &argv, NULL);
|
|
||||||
|
|
||||||
g_test_add_func ("/test-keymap-generation/check-xkb", test_check_xkb);
|
|
||||||
|
|
||||||
return g_test_run ();
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user