diff options
Diffstat (limited to 'runtime/test/gameinput_test.cpp')
| -rw-r--r-- | runtime/test/gameinput_test.cpp | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/runtime/test/gameinput_test.cpp b/runtime/test/gameinput_test.cpp index 1389b8f6d..1fab89b5a 100644 --- a/runtime/test/gameinput_test.cpp +++ b/runtime/test/gameinput_test.cpp | |||
| @@ -998,6 +998,7 @@ struct FakeHaptic { | |||
| 998 | SDL_HAPTIC_SAWTOOTHUP | SDL_HAPTIC_SAWTOOTHDOWN | SDL_HAPTIC_RAMP | SDL_HAPTIC_SPRING | | 998 | SDL_HAPTIC_SAWTOOTHUP | SDL_HAPTIC_SAWTOOTHDOWN | SDL_HAPTIC_RAMP | SDL_HAPTIC_SPRING | |
| 999 | SDL_HAPTIC_FRICTION | SDL_HAPTIC_DAMPER | SDL_HAPTIC_INERTIA; | 999 | SDL_HAPTIC_FRICTION | SDL_HAPTIC_DAMPER | SDL_HAPTIC_INERTIA; |
| 1000 | int max_effects = 8; | 1000 | int max_effects = 8; |
| 1001 | int create_result = 1; // what create returns; negative is SDL refusing the effect | ||
| 1001 | int opens = 0, closes = 0, creates = 0, updates = 0, runs = 0, stops = 0, destroys = 0; | 1002 | int opens = 0, closes = 0, creates = 0, updates = 0, runs = 0, stops = 0, destroys = 0; |
| 1002 | int gain_calls = 0, last_gain = -1; | 1003 | int gain_calls = 0, last_gain = -1; |
| 1003 | uint32_t last_iterations = 0; | 1004 | uint32_t last_iterations = 0; |
| @@ -1017,8 +1018,12 @@ int fake_max_effects(void* h) { return static_cast<FakeHaptic*>(h)->max_effects; | |||
| 1017 | int fake_create(void* h, const void* e) { | 1018 | int fake_create(void* h, const void* e) { |
| 1018 | FakeHaptic* f = static_cast<FakeHaptic*>(h); | 1019 | FakeHaptic* f = static_cast<FakeHaptic*>(h); |
| 1019 | ++f->creates; | 1020 | ++f->creates; |
| 1021 | if (f->create_result < 0) { | ||
| 1022 | SDL_SetError("fake: refused"); | ||
| 1023 | return -1; | ||
| 1024 | } | ||
| 1020 | f->last = *static_cast<const SDL_HapticEffect*>(e); | 1025 | f->last = *static_cast<const SDL_HapticEffect*>(e); |
| 1021 | return 1; | 1026 | return f->create_result; |
| 1022 | } | 1027 | } |
| 1023 | bool fake_update(void* h, int, const void* e) { | 1028 | bool fake_update(void* h, int, const void* e) { |
| 1024 | FakeHaptic* f = static_cast<FakeHaptic*>(h); | 1029 | FakeHaptic* f = static_cast<FakeHaptic*>(h); |
| @@ -1114,6 +1119,9 @@ void test_force_feedback(IGameInput* input) { | |||
| 1114 | const int runs0 = g_fake.runs; | 1119 | const int runs0 = g_fake.runs; |
| 1115 | rt::gameinput::poll(); | 1120 | rt::gameinput::poll(); |
| 1116 | check(g_fake.creates == 1 && g_fake.runs == runs0 + 1, "force feedback: the poll thread creates and runs the effect"); | 1121 | check(g_fake.creates == 1 && g_fake.runs == runs0 + 1, "force feedback: the poll thread creates and runs the effect"); |
| 1122 | rt::gameinput::OutputState sent{}; | ||
| 1123 | check(rt::gameinput::output_state(0, &sent) && sent.effect_id == 1 && sent.effect_ran && !sent.effect_error[0], | ||
| 1124 | "force feedback: the output state reports the effect SDL created and is running"); | ||
| 1117 | check(g_fake.last.type == SDL_HAPTIC_CONSTANT && g_fake.last.constant.level == 16384, | 1125 | check(g_fake.last.type == SDL_HAPTIC_CONSTANT && g_fake.last.constant.level == 16384, |
| 1118 | "force feedback: a constant 0.5 becomes SDL_HAPTIC_CONSTANT level 16384"); | 1126 | "force feedback: a constant 0.5 becomes SDL_HAPTIC_CONSTANT level 16384"); |
| 1119 | check(g_fake.last.constant.length == 60000 && g_fake.last_iterations == 0, | 1127 | check(g_fake.last.constant.length == 60000 && g_fake.last_iterations == 0, |
| @@ -1121,6 +1129,22 @@ void test_force_feedback(IGameInput* input) { | |||
| 1121 | rt::gameinput::poll(); | 1129 | rt::gameinput::poll(); |
| 1122 | check(g_fake.runs == runs0 + 1, "force feedback: an unchanged effect is not re-sent every poll"); | 1130 | check(g_fake.runs == runs0 + 1, "force feedback: an unchanged effect is not re-sent every poll"); |
| 1123 | 1131 | ||
| 1132 | // SDL refusing an effect is visible, not swallowed: the output state carries the failure and SDL's error. | ||
| 1133 | g_fake.create_result = -1; | ||
| 1134 | IGameInputForceFeedbackEffect* refused = nullptr; | ||
| 1135 | check(dev->CreateForceFeedbackEffect(0, ¶ms, reinterpret_cast<void**>(&refused)) == S_OK && refused, | ||
| 1136 | "force feedback: GameInput accepts an effect SDL will refuse"); | ||
| 1137 | if (refused) { | ||
| 1138 | rt::gameinput::poll(); | ||
| 1139 | rt::gameinput::OutputState refused_out{}; | ||
| 1140 | check(rt::gameinput::output_state(0, &refused_out) && refused_out.effect_id < 0 && !refused_out.effect_ran && | ||
| 1141 | std::strstr(refused_out.effect_error, "fake: refused"), | ||
| 1142 | "force feedback: SDL refusing the effect is recorded with its error"); | ||
| 1143 | refused->Release(); | ||
| 1144 | rt::gameinput::poll(); // the released effect leaves the device | ||
| 1145 | } | ||
| 1146 | g_fake.create_result = 1; | ||
| 1147 | |||
| 1124 | params.data.constant.magnitude.linearX = -1.0f; | 1148 | params.data.constant.magnitude.linearX = -1.0f; |
| 1125 | check(effect->SetParams(¶ms), "force feedback: SetParams"); | 1149 | check(effect->SetParams(¶ms), "force feedback: SetParams"); |
| 1126 | rt::gameinput::poll(); | 1150 | rt::gameinput::poll(); |