Skip to content

Commit

Permalink
Add tests/src/manipulator_mouse_basic
Browse files Browse the repository at this point in the history
  • Loading branch information
tekezo committed Sep 21, 2023
1 parent 17eb630 commit 817a788
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 0 deletions.
10 changes: 10 additions & 0 deletions tests/src/manipulator_mouse_basic/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
cmake_minimum_required (VERSION 3.9)

include (../../tests.cmake)

project (karabiner_test)

add_executable(
karabiner_test
src/test.cpp
)
6 changes: 6 additions & 0 deletions tests/src/manipulator_mouse_basic/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
all: build_make
./build/karabiner_test

clean: clean_builds

include ../Makefile.rules
1 change: 1 addition & 0 deletions tests/src/manipulator_mouse_basic/json/errors.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
["errors/mouse_basic_errors.jsonc"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[
// mouse_basic

{
"class": "mouse_basic",
"input": null,
"error": "json must be object, but is `null`"
},

// flip

{
"class": "mouse_basic",
"input": {
"flip": null
},
"error": "`flip` must be array, but is `null`"
},

{
"class": "mouse_basic",
"input": {
"flip": [null]
},
"error": "items in `flip` must be string, but is `null`"
},

// unknown key

{
"class": "mouse_basic",
"input": {
"option": {}
},
"error": "unknown key `option` in `{\"option\":{}}`"
}
]
41 changes: 41 additions & 0 deletions tests/src/manipulator_mouse_basic/src/errors_test.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#include "../../share/json_helper.hpp"
#include "manipulator/manipulators/mouse_basic/mouse_basic.hpp"
#include "manipulator/types.hpp"
#include <boost/ut.hpp>

namespace {
using namespace boost::ut;
using namespace boost::ut::literals;

void handle_json(const nlohmann::json& json) {
auto c = json.at("class").get<std::string>();
if (c == "mouse_basic") {
krbn::core_configuration::details::complex_modifications_parameters parameters;
krbn::manipulator::manipulators::mouse_basic::mouse_basic(json.at("input"), parameters);
} else {
expect(false);
}
}
} // namespace

void run_errors_test(void) {
using namespace boost::ut;
using namespace boost::ut::literals;

"errors"_test = [] {
auto json = krbn::unit_testing::json_helper::load_jsonc("json/errors.jsonc");
for (const auto& j : json) {
auto error_json = krbn::unit_testing::json_helper::load_jsonc("json/" + j.get<std::string>());
for (const auto& e : error_json) {
try {
handle_json(e);
expect(false);
} catch (pqrs::json::unmarshal_error& ex) {
expect(std::string_view(e.at("error").get<std::string>()) == ex.what());
} catch (...) {
expect(false);
}
}
}
};
}
6 changes: 6 additions & 0 deletions tests/src/manipulator_mouse_basic/src/test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include "errors_test.hpp"

int main(void) {
run_errors_test();
return 0;
}

0 comments on commit 817a788

Please sign in to comment.