tests: Use project code formatting on tests

v2: Increase line length, and add to formatting script (rpavlik)
This commit is contained in:
Jakob Bornecrantz 2020-06-17 10:58:29 +01:00 committed by Ryan Pavlik
parent 726e446421
commit 3055102217
5 changed files with 328 additions and 232 deletions

View file

@ -31,6 +31,7 @@ fi
src/xrt/ipc \ src/xrt/ipc \
src/xrt/state_trackers \ src/xrt/state_trackers \
src/xrt/targets \ src/xrt/targets \
tests \
\( -name "*.c" -o -name "*.cpp" -o -name "*.h" -o -name "*.hpp" \) \ \( -name "*.c" -o -name "*.cpp" -o -name "*.h" -o -name "*.hpp" \) \
-exec ${CLANGFORMAT} -i -style=file \{\} + -exec ${CLANGFORMAT} -i -style=file \{\} +
) )

View file

@ -1,6 +1,6 @@
--- ---
# SPDX-LicenseIdentifier: CC0-1.0 # SPDX-LicenseIdentifier: CC0-1.0
# SPDX-FileCopyrightText: 2019, Collabora, Ltd. # SPDX-FileCopyrightText: 2020, Collabora, Ltd.
Language: Cpp Language: Cpp
BasedOnStyle: LLVM BasedOnStyle: LLVM
Standard: Auto Standard: Auto

51
tests/.clang-format Normal file
View file

@ -0,0 +1,51 @@
---
# SPDX-LicenseIdentifier: CC0-1.0
# SPDX-FileCopyrightText: 2020, Collabora, Ltd.
Language: Cpp
BasedOnStyle: LLVM
Standard: Auto
# Includes
SortIncludes: false
# Spacing and Blank Lines
DerivePointerAlignment: false
PointerAlignment: Right
#AlignEscapedNewlines: DontAlign
#AlignConsecutiveDeclarations: false
#AlignConsecutiveAssignments: false
MaxEmptyLinesToKeep: 3
# Indentation
IndentWidth: 8
TabWidth: 8
UseTab: ForIndentation
AccessModifierOffset: -8
IndentCaseLabels: false
NamespaceIndentation: Inner
# Line length/reflow
# Longer for tests because of high levels of indentation
ColumnLimit: 120
ReflowComments: true
# Line breaks
AlwaysBreakAfterReturnType: All
AllowShortFunctionsOnASingleLine: Empty
AllowShortIfStatementsOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: true
AlwaysBreakBeforeMultilineStrings: true
BreakBeforeBraces: Custom
BraceWrapping:
AfterEnum: true
AfterStruct: true
AfterClass: true
SplitEmptyFunction: false
AfterFunction: true
AfterNamespace: false
# false means either "all on one line" or "each on their own",
# won't put more than one on a line if they don't all fit.
BinPackArguments: true
BinPackParameters: false

View file

@ -16,7 +16,8 @@
using Catch::Generators::values; using Catch::Generators::values;
TEST_CASE("input_transform") { TEST_CASE("input_transform")
{
struct oxr_logger log; struct oxr_logger log;
oxr_log_init(&log, "test"); oxr_log_init(&log, "test");
struct oxr_sink_logger slog = {}; struct oxr_sink_logger slog = {};
@ -27,245 +28,288 @@ TEST_CASE("input_transform") {
oxr_input_value_tagged input = {}; oxr_input_value_tagged input = {};
oxr_input_value_tagged output = {}; oxr_input_value_tagged output = {};
SECTION("Float action") { SECTION("Float action")
{
XrActionType action_type = XR_ACTION_TYPE_FLOAT_INPUT; XrActionType action_type = XR_ACTION_TYPE_FLOAT_INPUT;
SECTION("From Vec1 -1 to 1 identity") {
SECTION("From Vec1 -1 to 1 identity")
{
input.type = XRT_INPUT_TYPE_VEC1_MINUS_ONE_TO_ONE; input.type = XRT_INPUT_TYPE_VEC1_MINUS_ONE_TO_ONE;
CHECK(oxr_input_transform_create_chain(
&log, &slog, input.type, action_type, "float_action", CHECK(oxr_input_transform_create_chain(&log, &slog, input.type, action_type, "float_action",
"/dummy_float", &transforms, &num_transforms)); "/dummy_float", &transforms, &num_transforms));
// Just identity // Just identity
CHECK(num_transforms == 1); CHECK(num_transforms == 1);
CHECK(transforms != nullptr); CHECK(transforms != nullptr);
SECTION("Roundtrip") { SECTION("Roundtrip")
auto value = {
GENERATE(values({-1.f, -0.5f, 0.f, -0.f, 0.5f, 1.f})); auto value = GENERATE(values({-1.f, -0.5f, 0.f, -0.f, 0.5f, 1.f}));
input.value.vec1.x = value; input.value.vec1.x = value;
CHECK(oxr_input_transform_process(transforms, num_transforms,
&input, &output)); CHECK(oxr_input_transform_process(transforms, num_transforms, &input, &output));
CHECK(input.value.vec1.x == output.value.vec1.x); CHECK(input.value.vec1.x == output.value.vec1.x);
} }
} }
SECTION("From Vec1 0 to 1 identity") { SECTION("From Vec1 0 to 1 identity")
{
input.type = XRT_INPUT_TYPE_VEC1_ZERO_TO_ONE; input.type = XRT_INPUT_TYPE_VEC1_ZERO_TO_ONE;
CHECK(oxr_input_transform_create_chain(
&log, &slog, input.type, action_type, "float_action", CHECK(oxr_input_transform_create_chain(&log, &slog, input.type, action_type, "float_action",
"/dummy_float", &transforms, &num_transforms)); "/dummy_float", &transforms, &num_transforms));
// Just identity // Just identity
CHECK(num_transforms == 1); CHECK(num_transforms == 1);
CHECK(transforms != nullptr); CHECK(transforms != nullptr);
SECTION("Roundtrip") { SECTION("Roundtrip")
{
auto value = GENERATE(values({0.f, -0.f, 0.5f, 1.f})); auto value = GENERATE(values({0.f, -0.f, 0.5f, 1.f}));
input.value.vec1.x = value; input.value.vec1.x = value;
CHECK(oxr_input_transform_process(transforms, num_transforms,
&input, &output)); CHECK(oxr_input_transform_process(transforms, num_transforms, &input, &output));
CHECK(input.value.vec1.x == output.value.vec1.x); CHECK(input.value.vec1.x == output.value.vec1.x);
} }
} }
SECTION("From Vec2 input") { SECTION("From Vec2 input")
{
input.type = XRT_INPUT_TYPE_VEC2_MINUS_ONE_TO_ONE; input.type = XRT_INPUT_TYPE_VEC2_MINUS_ONE_TO_ONE;
input.value.vec2.x = -1; input.value.vec2.x = -1;
input.value.vec2.y = 1; input.value.vec2.y = 1;
SECTION("path component x") {
CHECK(oxr_input_transform_create_chain( SECTION("path component x")
&log, &slog, input.type, action_type, "float_action", {
"/dummy_vec2/x", &transforms, &num_transforms)); CHECK(oxr_input_transform_create_chain(&log, &slog, input.type, action_type,
"float_action", "/dummy_vec2/x", &transforms,
&num_transforms));
// Identity and a get-x // Identity and a get-x
CHECK(num_transforms == 2); CHECK(num_transforms == 2);
CHECK(transforms != nullptr); CHECK(transforms != nullptr);
CHECK(oxr_input_transform_process(transforms, num_transforms, CHECK(oxr_input_transform_process(transforms, num_transforms, &input, &output));
&input, &output));
CHECK(input.value.vec2.x == output.value.vec1.x); CHECK(input.value.vec2.x == output.value.vec1.x);
} }
SECTION("path component y") {
CHECK(oxr_input_transform_create_chain( SECTION("path component y")
&log, &slog, input.type, action_type, "float_action", {
"/dummy_vec2/y", &transforms, &num_transforms)); CHECK(oxr_input_transform_create_chain(&log, &slog, input.type, action_type,
"float_action", "/dummy_vec2/y", &transforms,
&num_transforms));
// Identity and a get-y // Identity and a get-y
CHECK(num_transforms == 2); CHECK(num_transforms == 2);
CHECK(transforms != nullptr); CHECK(transforms != nullptr);
CHECK(oxr_input_transform_process(transforms, num_transforms, CHECK(oxr_input_transform_process(transforms, num_transforms, &input, &output));
&input, &output));
CHECK(input.value.vec2.y == output.value.vec1.x); CHECK(input.value.vec2.y == output.value.vec1.x);
} }
SECTION("no component") {
CHECK_FALSE(oxr_input_transform_create_chain( SECTION("no component")
&log, &slog, input.type, action_type, "float_action", {
"/dummy_vec2", &transforms, &num_transforms)); CHECK_FALSE(oxr_input_transform_create_chain(&log, &slog, input.type, action_type,
"float_action", "/dummy_vec2", &transforms,
&num_transforms));
// Shouldn't make a transform, not possible // Shouldn't make a transform, not possible
CHECK(num_transforms == 0); CHECK(num_transforms == 0);
CHECK(transforms == nullptr); CHECK(transforms == nullptr);
// shouldn't do anything, but shouldn't explode. // shouldn't do anything, but shouldn't explode.
CHECK_FALSE(oxr_input_transform_process( CHECK_FALSE(oxr_input_transform_process(transforms, num_transforms, &input, &output));
transforms, num_transforms, &input, &output));
} }
} }
SECTION("From bool input") { SECTION("From bool input")
{
input.type = XRT_INPUT_TYPE_BOOLEAN; input.type = XRT_INPUT_TYPE_BOOLEAN;
CHECK(oxr_input_transform_create_chain( CHECK(oxr_input_transform_create_chain(&log, &slog, input.type, action_type, "float_action",
&log, &slog, input.type, action_type, "float_action",
"/dummy_bool", &transforms, &num_transforms)); "/dummy_bool", &transforms, &num_transforms));
// Identity and a bool-to-float // Identity and a bool-to-float
CHECK(num_transforms == 2); CHECK(num_transforms == 2);
CHECK(transforms != nullptr); CHECK(transforms != nullptr);
SECTION("False") { SECTION("False")
{
input.value.boolean = false; input.value.boolean = false;
CHECK(oxr_input_transform_process(transforms, num_transforms,
&input, &output)); CHECK(oxr_input_transform_process(transforms, num_transforms, &input, &output));
CHECK(0.0f == output.value.vec1.x); CHECK(0.0f == output.value.vec1.x);
} }
SECTION("True") {
SECTION("True")
{
input.value.boolean = true; input.value.boolean = true;
CHECK(oxr_input_transform_process(transforms, num_transforms,
&input, &output)); CHECK(oxr_input_transform_process(transforms, num_transforms, &input, &output));
CHECK(1.0f == output.value.vec1.x); CHECK(1.0f == output.value.vec1.x);
} }
} }
} }
SECTION("Bool action") { SECTION("Bool action")
{
XrActionType action_type = XR_ACTION_TYPE_BOOLEAN_INPUT; XrActionType action_type = XR_ACTION_TYPE_BOOLEAN_INPUT;
SECTION("From Bool identity") { SECTION("From Bool identity")
{
input.type = XRT_INPUT_TYPE_BOOLEAN; input.type = XRT_INPUT_TYPE_BOOLEAN;
CHECK(oxr_input_transform_create_chain(
&log, &slog, input.type, action_type, "bool_action", CHECK(oxr_input_transform_create_chain(&log, &slog, input.type, action_type, "bool_action",
"/dummy_bool", &transforms, &num_transforms)); "/dummy_bool", &transforms, &num_transforms));
CHECK(num_transforms == 1); CHECK(num_transforms == 1);
CHECK(transforms != nullptr); CHECK(transforms != nullptr);
SECTION("Roundtrip") { SECTION("Roundtrip")
{
auto value = GENERATE(values({0, 1})); auto value = GENERATE(values({0, 1}));
input.value.boolean = bool(value); input.value.boolean = bool(value);
CHECK(oxr_input_transform_process(transforms, num_transforms, CHECK(oxr_input_transform_process(transforms, num_transforms, &input, &output));
&input, &output));
CHECK(input.value.boolean == output.value.boolean); CHECK(input.value.boolean == output.value.boolean);
} }
} }
SECTION("From Vec1 -1 to 1") { SECTION("From Vec1 -1 to 1")
{
input.type = XRT_INPUT_TYPE_VEC1_MINUS_ONE_TO_ONE; input.type = XRT_INPUT_TYPE_VEC1_MINUS_ONE_TO_ONE;
CHECK(oxr_input_transform_create_chain(
&log, &slog, input.type, action_type, "bool_action", CHECK(oxr_input_transform_create_chain(&log, &slog, input.type, action_type, "bool_action",
"/dummy_float", &transforms, &num_transforms)); "/dummy_float", &transforms, &num_transforms));
CHECK(num_transforms == 2); CHECK(num_transforms == 2);
CHECK(transforms != nullptr); CHECK(transforms != nullptr);
SECTION("True") { SECTION("True")
{
auto value = GENERATE(values({0.5f, 1.f})); auto value = GENERATE(values({0.5f, 1.f}));
input.value.vec1.x = value; input.value.vec1.x = value;
CHECK(oxr_input_transform_process(transforms, num_transforms,
&input, &output)); CHECK(oxr_input_transform_process(transforms, num_transforms, &input, &output));
CHECK(output.value.boolean == true); CHECK(output.value.boolean == true);
} }
SECTION("False") {
SECTION("False")
{
auto value = GENERATE(values({0.0f, -1.f})); auto value = GENERATE(values({0.0f, -1.f}));
input.value.vec1.x = value; input.value.vec1.x = value;
CHECK(oxr_input_transform_process(transforms, num_transforms,
&input, &output)); CHECK(oxr_input_transform_process(transforms, num_transforms, &input, &output));
CHECK(output.value.boolean == false); CHECK(output.value.boolean == false);
} }
} }
SECTION("From Vec1 0 to 1") { SECTION("From Vec1 0 to 1")
{
input.type = XRT_INPUT_TYPE_VEC1_ZERO_TO_ONE; input.type = XRT_INPUT_TYPE_VEC1_ZERO_TO_ONE;
CHECK(oxr_input_transform_create_chain(
&log, &slog, input.type, action_type, "bool_action", CHECK(oxr_input_transform_create_chain(&log, &slog, input.type, action_type, "bool_action",
"/dummy_float", &transforms, &num_transforms)); "/dummy_float", &transforms, &num_transforms));
CHECK(num_transforms == 2); CHECK(num_transforms == 2);
CHECK(transforms != nullptr); CHECK(transforms != nullptr);
SECTION("True") { SECTION("True")
{
auto value = GENERATE(values({0.95f, 1.f})); auto value = GENERATE(values({0.95f, 1.f}));
input.value.vec1.x = value; input.value.vec1.x = value;
CHECK(oxr_input_transform_process(transforms, num_transforms,
&input, &output)); CHECK(oxr_input_transform_process(transforms, num_transforms, &input, &output));
CHECK(output.value.boolean == true); CHECK(output.value.boolean == true);
} }
SECTION("False") {
SECTION("False")
{
auto value = GENERATE(values({0.0f, 0.5f})); auto value = GENERATE(values({0.0f, 0.5f}));
input.value.vec1.x = value; input.value.vec1.x = value;
CHECK(oxr_input_transform_process(transforms, num_transforms,
&input, &output)); CHECK(oxr_input_transform_process(transforms, num_transforms, &input, &output));
CHECK(output.value.boolean == false); CHECK(output.value.boolean == false);
} }
} }
SECTION("From Vec2") {
SECTION("From Vec2")
{
input.type = XRT_INPUT_TYPE_VEC2_MINUS_ONE_TO_ONE; input.type = XRT_INPUT_TYPE_VEC2_MINUS_ONE_TO_ONE;
input.value.vec2.x = -1; input.value.vec2.x = -1;
input.value.vec2.y = 1; input.value.vec2.y = 1;
SECTION("x") {
CHECK(oxr_input_transform_create_chain( SECTION("x")
&log, &slog, input.type, action_type, "float_action", {
"/dummy_vec2/x", &transforms, &num_transforms)); CHECK(oxr_input_transform_create_chain(&log, &slog, input.type, action_type,
"float_action", "/dummy_vec2/x", &transforms,
&num_transforms));
CHECK(num_transforms == 3); CHECK(num_transforms == 3);
CHECK(transforms != nullptr); CHECK(transforms != nullptr);
CHECK(oxr_input_transform_process(transforms, num_transforms, CHECK(oxr_input_transform_process(transforms, num_transforms, &input, &output));
&input, &output));
CHECK(false == output.value.boolean); CHECK(false == output.value.boolean);
} }
SECTION("y") {
CHECK(oxr_input_transform_create_chain( SECTION("y")
&log, &slog, input.type, action_type, "float_action", {
"/dummy_vec2/y", &transforms, &num_transforms)); CHECK(oxr_input_transform_create_chain(&log, &slog, input.type, action_type,
"float_action", "/dummy_vec2/y", &transforms,
&num_transforms));
CHECK(num_transforms == 3); CHECK(num_transforms == 3);
CHECK(transforms != nullptr); CHECK(transforms != nullptr);
CHECK(oxr_input_transform_process(transforms, num_transforms, CHECK(oxr_input_transform_process(transforms, num_transforms, &input, &output));
&input, &output));
CHECK(true == output.value.boolean); CHECK(true == output.value.boolean);
} }
SECTION("no component") {
CHECK_FALSE(oxr_input_transform_create_chain( SECTION("no component")
&log, &slog, input.type, action_type, "float_action", {
"/dummy", &transforms, &num_transforms)); CHECK_FALSE(oxr_input_transform_create_chain(&log, &slog, input.type, action_type,
"float_action", "/dummy", &transforms,
&num_transforms));
// Shouldn't make a transform, not possible // Shouldn't make a transform, not possible
CHECK(num_transforms == 0); CHECK(num_transforms == 0);
CHECK(transforms == nullptr); CHECK(transforms == nullptr);
// shouldn't do anything, but shouldn't explode. // shouldn't do anything, but shouldn't explode.
CHECK_FALSE(oxr_input_transform_process( CHECK_FALSE(oxr_input_transform_process(transforms, num_transforms, &input, &output));
transforms, num_transforms, &input, &output));
} }
} }
} }
SECTION("Pose action") { SECTION("Pose action")
{
XrActionType action_type = XR_ACTION_TYPE_POSE_INPUT; XrActionType action_type = XR_ACTION_TYPE_POSE_INPUT;
SECTION("From Pose identity") {
SECTION("From Pose identity")
{
input.type = XRT_INPUT_TYPE_POSE; input.type = XRT_INPUT_TYPE_POSE;
CHECK(oxr_input_transform_create_chain( CHECK(oxr_input_transform_create_chain(&log, &slog, input.type, action_type, "pose_action",
&log, &slog, input.type, action_type, "pose_action",
"/dummy_pose", &transforms, &num_transforms)); "/dummy_pose", &transforms, &num_transforms));
// Identity, just so this binding doesn't get culled. // Identity, just so this binding doesn't get culled.
CHECK(num_transforms == 1); CHECK(num_transforms == 1);
} }
SECTION("From other input") {
auto input_type = GENERATE(values( SECTION("From other input")
{XRT_INPUT_TYPE_BOOLEAN, XRT_INPUT_TYPE_VEC1_MINUS_ONE_TO_ONE, {
auto input_type = GENERATE(values({
XRT_INPUT_TYPE_BOOLEAN,
XRT_INPUT_TYPE_VEC1_MINUS_ONE_TO_ONE,
XRT_INPUT_TYPE_VEC1_ZERO_TO_ONE, XRT_INPUT_TYPE_VEC1_ZERO_TO_ONE,
XRT_INPUT_TYPE_VEC2_MINUS_ONE_TO_ONE, XRT_INPUT_TYPE_VEC2_MINUS_ONE_TO_ONE,
XRT_INPUT_TYPE_VEC3_MINUS_ONE_TO_ONE})); XRT_INPUT_TYPE_VEC3_MINUS_ONE_TO_ONE,
}));
CAPTURE(input_type); CAPTURE(input_type);
input.type = input_type; input.type = input_type;
CHECK_FALSE(oxr_input_transform_create_chain(
&log, &slog, input.type, action_type, "pose_action", "/dummy", CHECK_FALSE(oxr_input_transform_create_chain(&log, &slog, input.type, action_type,
&transforms, &num_transforms)); "pose_action", "/dummy", &transforms,
&num_transforms));
// not possible // not possible
CHECK(num_transforms == 0); CHECK(num_transforms == 0);
CHECK(transforms == nullptr); CHECK(transforms == nullptr);
} }
} }
oxr_log_slog(&log, &slog); oxr_log_slog(&log, &slog);
oxr_input_transform_destroy(&transforms); oxr_input_transform_destroy(&transforms);
CHECK(NULL == transforms); CHECK(NULL == transforms);