static void testButtonBindings() { InputMap * inputMap; inputMap = InputMap_create(); verifyButtonNotBound(inputMap, ATOM("a"), 0, 0, 0, __LINE__); verifyButtonNotBound(inputMap, ATOM("a"), 0, 0, 1, __LINE__); verifyButtonNotBound(inputMap, ATOM("a"), 1, 1, 1, __LINE__); verifyButtonNotBound(inputMap, ATOM("b"), 0, 0, 0, __LINE__); inputMap->bindButton(inputMap, ATOM("a"), 0, 0, 0); verifyButtonBound(inputMap, ATOM("a"), 0, 0, 0, __LINE__); inputMap->bindButton(inputMap, ATOM("a"), 0, 0, 1); verifyButtonBound(inputMap, ATOM("a"), 0, 0, 0, __LINE__); verifyButtonBound(inputMap, ATOM("a"), 0, 0, 1, __LINE__); inputMap->bindButton(inputMap, ATOM("a"), 1, 1, 1); verifyButtonBound(inputMap, ATOM("a"), 0, 0, 0, __LINE__); verifyButtonBound(inputMap, ATOM("a"), 0, 0, 1, __LINE__); verifyButtonBound(inputMap, ATOM("a"), 1, 1, 1, __LINE__); inputMap->bindButton(inputMap, ATOM("b"), 0, 0, 0); verifyButtonBound(inputMap, ATOM("a"), 0, 0, 0, __LINE__); verifyButtonBound(inputMap, ATOM("a"), 0, 0, 1, __LINE__); verifyButtonBound(inputMap, ATOM("a"), 1, 1, 1, __LINE__); verifyButtonBound(inputMap, ATOM("b"), 0, 0, 0, __LINE__); inputMap->unbindButton(inputMap, ATOM("a"), 0, 0, 0); verifyButtonNotBound(inputMap, ATOM("a"), 0, 0, 0, __LINE__); verifyButtonBound(inputMap, ATOM("a"), 0, 0, 1, __LINE__); verifyButtonBound(inputMap, ATOM("a"), 1, 1, 1, __LINE__); verifyButtonBound(inputMap, ATOM("b"), 0, 0, 0, __LINE__); }
static void testSerialization() { InputMap inputMap; TestSerializationContext * context; jmp_buf jmpEnv; context = TestSerializationContext_create(&jmpEnv); if (setjmp(jmpEnv) != 0) { TestCase_assert(false, "%s", context->error); } InputMap_init(&inputMap); context->expectCall(context, context->beginStructure, "input_map"); context->expectCall(context, context->writeUInt16, "format_version", INPUT_MAP_SERIALIZATION_FORMAT_VERSION); context->expectCall(context, context->beginArray, "keyboard_bindings"); context->expectCall(context, context->endArray); context->expectCall(context, context->beginArray, "gamepad_maps"); context->expectCall(context, context->endArray); context->expectCall(context, context->endStructure); InputMap_serialize(&inputMap, context); context->finish(context); context->dispose(context); inputMap.dispose(&inputMap); context = TestSerializationContext_create(&jmpEnv); if (setjmp(jmpEnv) != 0) { TestCase_assert(false, "%s", context->error); } InputMap_init(&inputMap); inputMap.bindKey(&inputMap, ATOM("a"), 1, 2); inputMap.bindKey(&inputMap, ATOM("b"), 3, 4); inputMap.bindButton(&inputMap, ATOM("a"), 1, 2, 3); inputMap.bindButton(&inputMap, ATOM("b"), 1, 2, 4); inputMap.bindButton(&inputMap, ATOM("c"), 4, 5, 6); inputMap.bindAxis(&inputMap, ATOM("a"), 1, 2, 3, 0.5f, 0.5f); inputMap.bindAxis(&inputMap, ATOM("b"), 1, 2, 4, 0.5f, 0.5f); inputMap.bindAxis(&inputMap, ATOM("c"), 4, 5, 6, 1.0f, 0.0f); context->expectCall(context, context->beginStructure, "input_map"); context->expectCall(context, context->writeUInt16, "format_version", INPUT_MAP_SERIALIZATION_FORMAT_VERSION); context->expectCall(context, context->beginArray, "keyboard_bindings"); context->expectCall(context, context->beginStructure, NULL); context->expectCall(context, context->writeString, "action", "a"); context->expectCall(context, context->writeUInt32, "key_code", 1); context->expectCall(context, context->writeUInt32, "char_code", 2); context->expectCall(context, context->endStructure); context->expectCall(context, context->beginStructure, NULL); context->expectCall(context, context->writeString, "action", "b"); context->expectCall(context, context->writeUInt32, "key_code", 3); context->expectCall(context, context->writeUInt32, "char_code", 4); context->expectCall(context, context->endStructure); context->expectCall(context, context->endArray); context->expectCall(context, context->beginArray, "gamepad_maps"); context->expectCall(context, context->beginStructure, NULL); context->expectCall(context, context->writeInt32, "vendor_id", 1); context->expectCall(context, context->writeInt32, "product_id", 2); context->expectCall(context, context->beginDictionary, "button_bindings"); context->expectCall(context, context->writeUInt32, "a", 3); context->expectCall(context, context->writeUInt32, "b", 4); context->expectCall(context, context->endDictionary); context->expectCall(context, context->beginArray, "axis_bindings"); context->expectCall(context, context->beginStructure, NULL); context->expectCall(context, context->writeString, "action", "a"); context->expectCall(context, context->writeUInt32, "axis_id", 3); context->expectCall(context, context->writeFloat, "trigger_threshold", 0.5f); context->expectCall(context, context->writeFloat, "release_threshold", 0.5f); context->expectCall(context, context->endStructure); context->expectCall(context, context->beginStructure, NULL); context->expectCall(context, context->writeString, "action", "b"); context->expectCall(context, context->writeUInt32, "axis_id", 4); context->expectCall(context, context->writeFloat, "trigger_threshold", 0.5f); context->expectCall(context, context->writeFloat, "release_threshold", 0.5f); context->expectCall(context, context->endStructure); context->expectCall(context, context->endArray); context->expectCall(context, context->endStructure); context->expectCall(context, context->beginStructure, NULL); context->expectCall(context, context->writeInt32, "vendor_id", 4); context->expectCall(context, context->writeInt32, "product_id", 5); context->expectCall(context, context->beginDictionary, "button_bindings"); context->expectCall(context, context->writeUInt32, "c", 6); context->expectCall(context, context->endDictionary); context->expectCall(context, context->beginArray, "axis_bindings"); context->expectCall(context, context->beginStructure, NULL); context->expectCall(context, context->writeString, "action", "c"); context->expectCall(context, context->writeUInt32, "axis_id", 6); context->expectCall(context, context->writeFloat, "trigger_threshold", 1.0f); context->expectCall(context, context->writeFloat, "release_threshold", 0.0f); context->expectCall(context, context->endStructure); context->expectCall(context, context->endArray); context->expectCall(context, context->endStructure); context->expectCall(context, context->endArray); context->expectCall(context, context->endStructure); InputMap_serialize(&inputMap, context); context->finish(context); context->dispose(context); inputMap.dispose(&inputMap); }