-
-
Notifications
You must be signed in to change notification settings - Fork 842
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests/src/manipulator_mouse_basic
- Loading branch information
Showing
6 changed files
with
101 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
["errors/mouse_basic_errors.jsonc"] |
37 changes: 37 additions & 0 deletions
37
tests/src/manipulator_mouse_basic/json/errors/mouse_basic_errors.jsonc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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\":{}}`" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |