Пример #1
0
static void testMemwriteRecording() {
	InputRecorder * inputRecorder;
	InputController * inputController;
	
	inputController = InputController_create(NULL, NULL);
	
	inputRecorder = InputRecorder_createWithMemwriteOutput(inputController, NULL, 0);
	TestCase_assert(inputRecorder->memwriteContext.length == 8, "Expected 8 but got " SIZE_T_FORMAT, inputRecorder->memwriteContext.length);
	TestCase_assert(!memcmp(inputRecorder->memwriteContext.data, "\x00\x00\x00\x00\x00\x00\x00\x00", 8), "Expected 0000 00000000 0000 but got %02X%02X %02X%02X%02X%02X %02X%02X", ((unsigned char *) inputRecorder->memwriteContext.data)[0], ((unsigned char *) inputRecorder->memwriteContext.data)[1], ((unsigned char *) inputRecorder->memwriteContext.data)[2], ((unsigned char *) inputRecorder->memwriteContext.data)[3], ((unsigned char *) inputRecorder->memwriteContext.data)[4], ((unsigned char *) inputRecorder->memwriteContext.data)[5], ((unsigned char *) inputRecorder->memwriteContext.data)[6], ((unsigned char *) inputRecorder->memwriteContext.data)[7]);
	inputRecorder->dispose(inputRecorder);
	
	inputRecorder = InputRecorder_createWithMemwriteOutput(inputController, "abcd", 4);
	TestCase_assert(inputRecorder->memwriteContext.length == 12, "Expected 12 but got " SIZE_T_FORMAT, inputRecorder->memwriteContext.length);
	TestCase_assert(!memcmp(inputRecorder->memwriteContext.data, "\x00\x00\x04\x00\x00\x00""abcd\x00\x00", 12), "Expected 0000 04000000 61626364 0000 but got %02X%02X %02X%02X%02X%02X %02X%02X%02X%02X %02X%02X", ((unsigned char *) inputRecorder->memwriteContext.data)[0], ((unsigned char *) inputRecorder->memwriteContext.data)[1], ((unsigned char *) inputRecorder->memwriteContext.data)[2], ((unsigned char *) inputRecorder->memwriteContext.data)[3], ((unsigned char *) inputRecorder->memwriteContext.data)[4], ((unsigned char *) inputRecorder->memwriteContext.data)[5], ((unsigned char *) inputRecorder->memwriteContext.data)[6], ((unsigned char *) inputRecorder->memwriteContext.data)[7], ((unsigned char *) inputRecorder->memwriteContext.data)[8], ((unsigned char *) inputRecorder->memwriteContext.data)[9], ((unsigned char *) inputRecorder->memwriteContext.data)[10], ((unsigned char *) inputRecorder->memwriteContext.data)[11]);
	inputRecorder->dispose(inputRecorder);
	
	inputController->dispose(inputController);
	inputController = InputController_create(NULL, "a", "bc", NULL);
	
	inputRecorder = InputRecorder_createWithMemwriteOutput(inputController, NULL, 0);
	TestCase_assert(inputRecorder->memwriteContext.length == 13, "Expected 13 but got " SIZE_T_FORMAT, inputRecorder->memwriteContext.length);
	TestCase_assert(!memcmp(inputRecorder->memwriteContext.data, "\x00\x00\x00\x00\x00\x00\x02\x00""a\x00""bc\x00", 13), "Expected 0000 00000000 0200 6100 626300 but got %02X%02X %02X%02X%02X%02X %02X%02X %02X%02X %02X%02X%02X", ((unsigned char *) inputRecorder->memwriteContext.data)[0], ((unsigned char *) inputRecorder->memwriteContext.data)[1], ((unsigned char *) inputRecorder->memwriteContext.data)[2], ((unsigned char *) inputRecorder->memwriteContext.data)[3], ((unsigned char *) inputRecorder->memwriteContext.data)[4], ((unsigned char *) inputRecorder->memwriteContext.data)[5], ((unsigned char *) inputRecorder->memwriteContext.data)[6], ((unsigned char *) inputRecorder->memwriteContext.data)[7], ((unsigned char *) inputRecorder->memwriteContext.data)[8], ((unsigned char *) inputRecorder->memwriteContext.data)[9], ((unsigned char *) inputRecorder->memwriteContext.data)[10], ((unsigned char *) inputRecorder->memwriteContext.data)[11], ((unsigned char *) inputRecorder->memwriteContext.data)[12]);
	
	inputController->triggerAction(inputController, ATOM("a"));
	TestCase_assert(inputRecorder->memwriteContext.length == 19, "Expected 19 but got " SIZE_T_FORMAT, inputRecorder->memwriteContext.length);
	TestCase_assert(!memcmp(inputRecorder->memwriteContext.data + 13, "\x00\x00\x00\x00\x00\x00", 6), "Expected 00000000 0000 but got %02X%02X%02X%02X %02X%02X", ((unsigned char *) inputRecorder->memwriteContext.data)[13], ((unsigned char *) inputRecorder->memwriteContext.data)[14], ((unsigned char *) inputRecorder->memwriteContext.data)[15], ((unsigned char *) inputRecorder->memwriteContext.data)[16], ((unsigned char *) inputRecorder->memwriteContext.data)[17], ((unsigned char *) inputRecorder->memwriteContext.data)[18]);
	
	inputRecorder->nextFrame(inputRecorder);
	inputController->triggerAction(inputController, ATOM("bc"));
	TestCase_assert(inputRecorder->memwriteContext.length == 25, "Expected 25 but got " SIZE_T_FORMAT, inputRecorder->memwriteContext.length);
	TestCase_assert(!memcmp(inputRecorder->memwriteContext.data + 19, "\x01\x00\x00\x00\x01\x00", 6), "Expected 01000000 0100 but got %02X%02X%02X%02X %02X%02X", ((unsigned char *) inputRecorder->memwriteContext.data)[19], ((unsigned char *) inputRecorder->memwriteContext.data)[20], ((unsigned char *) inputRecorder->memwriteContext.data)[21], ((unsigned char *) inputRecorder->memwriteContext.data)[22], ((unsigned char *) inputRecorder->memwriteContext.data)[23], ((unsigned char *) inputRecorder->memwriteContext.data)[24]);
	
	inputRecorder->nextFrame(inputRecorder);
	inputRecorder->nextFrame(inputRecorder);
	inputRecorder->nextFrame(inputRecorder);
	inputController->releaseAction(inputController, ATOM("bc"));
	TestCase_assert(inputRecorder->memwriteContext.length == 31, "Expected 31 but got " SIZE_T_FORMAT, inputRecorder->memwriteContext.length);
	TestCase_assert(!memcmp(inputRecorder->memwriteContext.data + 25, "\x03\x00\x00\x00\x01\x00", 6), "Expected 03000000 0100 but got %02X%02X%02X%02X %02X%02X", ((unsigned char *) inputRecorder->memwriteContext.data)[25], ((unsigned char *) inputRecorder->memwriteContext.data)[26], ((unsigned char *) inputRecorder->memwriteContext.data)[27], ((unsigned char *) inputRecorder->memwriteContext.data)[28], ((unsigned char *) inputRecorder->memwriteContext.data)[29], ((unsigned char *) inputRecorder->memwriteContext.data)[30]);
	
	inputRecorder->dispose(inputRecorder);
	inputController->dispose(inputController);
}
Пример #2
0
static void testActionTriggers() {
    InputController * inputController;

    actionDownCallCount = actionUpCallCount = 0;
    inputController = InputController_create(NULL, "a", "b", NULL);
    EventDispatcher_registerForEvent(inputController->eventDispatcher, ATOM(INPUT_CONTROLLER_EVENT_ACTION_DOWN), actionDown, NULL);
    EventDispatcher_registerForEvent(inputController->eventDispatcher, ATOM(INPUT_CONTROLLER_EVENT_ACTION_UP), actionUp, NULL);

    lastActionID = NULL;
    TestCase_assert(!InputController_isActionTriggered(inputController, ATOM("a")), "Expected false but got true");
    inputController->triggerAction(inputController, ATOM("a"));
    TestCase_assert(actionDownCallCount == 1, "Expected 1 but got %u", actionDownCallCount);
    TestCase_assert(lastActionID == ATOM("a"), "Expected \"a\" (%p) but got \"%s\" (%p)", ATOM("a"), lastActionID, lastActionID);
    TestCase_assert(InputController_isActionTriggered(inputController, ATOM("a")), "Expected true but got false");

    inputController->triggerAction(inputController, ATOM("a"));
    TestCase_assert(actionDownCallCount == 1, "Expected 1 but got %u", actionDownCallCount);
    TestCase_assert(InputController_isActionTriggered(inputController, ATOM("a")), "Expected true but got false");

    lastActionID = NULL;
    inputController->releaseAction(inputController, ATOM("a"));
    TestCase_assert(actionUpCallCount == 1, "Expected 1 but got %u", actionUpCallCount);
    TestCase_assert(lastActionID == ATOM("a"), "Expected \"a\" (%p) but got \"%s\" (%p)", ATOM("a"), lastActionID, lastActionID);
    TestCase_assert(!InputController_isActionTriggered(inputController, ATOM("a")), "Expected false but got true");

    lastActionID = NULL;
    inputController->triggerAction(inputController, ATOM("a"));
    TestCase_assert(actionDownCallCount == 2, "Expected 2 but got %u", actionDownCallCount);
    TestCase_assert(lastActionID == ATOM("a"), "Expected \"a\" (%p) but got \"%s\" (%p)", ATOM("a"), lastActionID, lastActionID);
    TestCase_assert(InputController_isActionTriggered(inputController, ATOM("a")), "Expected true but got false");

    lastActionID = NULL;
    TestCase_assert(!InputController_isActionTriggered(inputController, ATOM("b")), "Expected false but got true");
    inputController->triggerAction(inputController, ATOM("b"));
    TestCase_assert(actionDownCallCount == 3, "Expected 3 but got %u", actionDownCallCount);
    TestCase_assert(lastActionID == ATOM("b"), "Expected \"b\" (%p) but got \"%s\" (%p)", ATOM("b"), lastActionID, lastActionID);
    TestCase_assert(InputController_isActionTriggered(inputController, ATOM("b")), "Expected true but got false");

    InputController_dispose(inputController);
}
Пример #3
0
static void testFileRecording() {
	InputRecorder * inputRecorder;
	InputController * inputController;
	const char * tempFilePath;
	int tempFD;
	unsigned char * fileContents;
	size_t fileLength;
	
	inputController = InputController_create(NULL, NULL);
	tempFilePath = temporaryFilePath("tmpXXXXXX", &tempFD);
	close(tempFD);
	
	inputRecorder = InputRecorder_createWithFileOutput(inputController, NULL, 0, tempFilePath);
	fileContents = readFileSimple(tempFilePath, &fileLength);
	TestCase_assert(fileContents != NULL, "Expected non-NULL but got NULL");
	TestCase_assert(fileLength == 8, "Expected 8 but got " SIZE_T_FORMAT, fileLength);
	TestCase_assert(!memcmp(fileContents, "\x00\x00\x00\x00\x00\x00\x00\x00", 8), "Expected 0000 00000000 0000 but got %02X%02X %02X%02X%02X%02X %02X%02X", fileContents[0], fileContents[1], fileContents[2], fileContents[3], fileContents[4], fileContents[5], fileContents[6], fileContents[7]);
	free(fileContents);
	inputRecorder->dispose(inputRecorder);
	
	inputRecorder = InputRecorder_createWithFileOutput(inputController, "abcd", 4, tempFilePath);
	fileContents = readFileSimple(tempFilePath, &fileLength);
	TestCase_assert(fileContents != NULL, "Expected non-NULL but got NULL");
	TestCase_assert(fileLength == 12, "Expected 12 but got " SIZE_T_FORMAT, fileLength);
	TestCase_assert(!memcmp(fileContents, "\x00\x00\x04\x00\x00\x00""abcd\x00\x00", 12), "Expected 0000 04000000 61626364 0000 but got %02X%02X %02X%02X%02X%02X %02X%02X%02X%02X %02X%02X", fileContents[0], fileContents[1], fileContents[2], fileContents[3], fileContents[4], fileContents[5], fileContents[6], fileContents[7], fileContents[8], fileContents[9], fileContents[10], fileContents[11]);
	free(fileContents);
	inputRecorder->dispose(inputRecorder);
	
	inputController->dispose(inputController);
	inputController = InputController_create(NULL, "a", "bc", NULL);
	
	inputRecorder = InputRecorder_createWithFileOutput(inputController, NULL, 0, tempFilePath);
	fileContents = readFileSimple(tempFilePath, &fileLength);
	TestCase_assert(fileContents != NULL, "Expected non-NULL but got NULL");
	TestCase_assert(fileLength == 13, "Expected 13 but got " SIZE_T_FORMAT, fileLength);
	TestCase_assert(!memcmp(fileContents, "\x00\x00\x00\x00\x00\x00\x02\x00""a\x00""bc\x00", 13), "Expected 0000 00000000 0200 6100 626300 but got %02X%02X %02X%02X%02X%02X %02X%02X %02X%02X %02X%02X%02X", fileContents[0], fileContents[1], fileContents[2], fileContents[3], fileContents[4], fileContents[5], fileContents[6], fileContents[7], fileContents[8], fileContents[9], fileContents[10], fileContents[11], fileContents[12]);
	free(fileContents);
	
	inputController->triggerAction(inputController, ATOM("a"));
	fileContents = readFileSimple(tempFilePath, &fileLength);
	TestCase_assert(fileContents != NULL, "Expected non-NULL but got NULL");
	TestCase_assert(fileLength == 19, "Expected 19 but got " SIZE_T_FORMAT, fileLength);
	TestCase_assert(!memcmp(fileContents + 13, "\x00\x00\x00\x00\x00\x00", 6), "Expected 00000000 0000 but got %02X%02X%02X%02X %02X%02X", fileContents[13], fileContents[14], fileContents[15], fileContents[16], fileContents[17], fileContents[18]);
	free(fileContents);
	
	inputRecorder->nextFrame(inputRecorder);
	inputController->triggerAction(inputController, ATOM("bc"));
	fileContents = readFileSimple(tempFilePath, &fileLength);
	TestCase_assert(fileContents != NULL, "Expected non-NULL but got NULL");
	TestCase_assert(fileLength == 25, "Expected 25 but got " SIZE_T_FORMAT, fileLength);
	TestCase_assert(!memcmp(fileContents + 19, "\x01\x00\x00\x00\x01\x00", 6), "Expected 01000000 0100 but got %02X%02X%02X%02X %02X%02X", fileContents[19], fileContents[20], fileContents[21], fileContents[22], fileContents[23], fileContents[24]);
	free(fileContents);
	
	inputRecorder->nextFrame(inputRecorder);
	inputRecorder->nextFrame(inputRecorder);
	inputRecorder->nextFrame(inputRecorder);
	inputController->releaseAction(inputController, ATOM("bc"));
	fileContents = readFileSimple(tempFilePath, &fileLength);
	TestCase_assert(fileContents != NULL, "Expected non-NULL but got NULL");
	TestCase_assert(fileLength == 31, "Expected 31 but got " SIZE_T_FORMAT, fileLength);
	TestCase_assert(!memcmp(fileContents + 25, "\x03\x00\x00\x00\x01\x00", 6), "Expected 03000000 0100 but got %02X%02X%02X%02X %02X%02X", fileContents[25], fileContents[26], fileContents[27], fileContents[28], fileContents[29], fileContents[30]);
	free(fileContents);
	
	inputRecorder->dispose(inputRecorder);
	inputController->dispose(inputController);
	unlink(tempFilePath);
}