Exemple #1
0
static void testKeyboardBindings() {
	InputMap * inputMap;
	
	inputMap = InputMap_create();
	verifyKeyNotBound(inputMap, ATOM("a"), 1, 3, __LINE__);
	verifyKeyNotBound(inputMap, ATOM("b"), 1, 2, __LINE__);
	
	inputMap->bindKey(inputMap, ATOM("a"), 1, 3);
	verifyKeyBound(inputMap, ATOM("a"), 1, 3, __LINE__);
	
	inputMap->bindKey(inputMap, ATOM("a"), 1, 2);
	verifyKeyBound(inputMap, ATOM("a"), 1, 2, __LINE__);
	TestCase_assert(!isKeyBound(inputMap, ATOM("a"), 1, 3), "Expected false but got true");
	
	inputMap->bindKey(inputMap, ATOM("a"), 2, 4);
	verifyKeyBound(inputMap, ATOM("a"), 1, 2, __LINE__);
	verifyKeyBound(inputMap, ATOM("a"), 2, 4, __LINE__);
	
	inputMap->bindKey(inputMap, ATOM("b"), 1, 2);
	verifyKeyBound(inputMap, ATOM("a"), 1, 2, __LINE__);
	verifyKeyBound(inputMap, ATOM("a"), 2, 4, __LINE__);
	verifyKeyBound(inputMap, ATOM("b"), 1, 2, __LINE__);
	
	inputMap->unbindKey(inputMap, ATOM("a"), 1);
	verifyKeyNotBound(inputMap, ATOM("a"), 1, 2, __LINE__);
	verifyKeyBound(inputMap, ATOM("a"), 2, 4, __LINE__);
	verifyKeyBound(inputMap, ATOM("b"), 1, 2, __LINE__);
}
Exemple #2
0
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);
}