tstMouseImpl.cpp revision 8d0e08b1554426514051150bb804899260631334
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync/* $Id$ */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync/** @file
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Main unit test - Mouse class.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync/*
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync * Copyright (C) 2011 Oracle Corporation
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync *
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * available from http://www.virtualbox.org. This file is free software;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * you can redistribute it and/or modify it under the terms of the GNU
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * General Public License (GPL) as published by the Free Software
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync/******************************************************************************
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync* Header Files *
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync******************************************************************************/
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#include "MouseImpl.h"
d200be7337d4aad2bec2961a885e856f7866d4f6vboxsync#include "VMMDev.h"
2624f7a939f765d1975a82f3072c272f7fa3548dvboxsync#include "DisplayImpl.h"
d200be7337d4aad2bec2961a885e856f7866d4f6vboxsync
d200be7337d4aad2bec2961a885e856f7866d4f6vboxsync#include <VBox/vmm/cfgm.h>
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync#include <VBox/vmm/pdmdrv.h>
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync#include <VBox/VMMDev.h>
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync#include <iprt/assert.h>
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#include <iprt/test.h>
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsyncNS_DECL_CLASSINFO(Mouse)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsyncNS_IMPL_THREADSAFE_ISUPPORTS1_CI(Mouse, IMouse)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsyncPDMIVMMDEVPORT VMMDevPort;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsyncclass TestVMMDev : public VMMDevMouseInterface
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync{
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync PPDMIVMMDEVPORT getVMMDevPort(void) { return &VMMDevPort; }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync};
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsyncclass TestDisplay : public DisplayMouseInterface
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync{
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync void getFramebufferDimensions(int32_t *px1, int32_t *py1,
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync int32_t *px2, int32_t *py2);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync int getScreenResolution(uint32_t cScreen, ULONG *pcx, ULONG *pcy,
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync ULONG *pcBPP);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync};
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsyncclass TestConsole : public ConsoleMouseInterface
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync{
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsyncpublic:
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync VMMDevMouseInterface *getVMMDevMouseInterface() { return &mVMMDev; }
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync DisplayMouseInterface *getDisplayMouseInterface() { return &mDisplay; }
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync /** @todo why on earth is this not implemented? */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync void onMouseCapabilityChange(BOOL supportsAbsolute, BOOL supportsRelative,
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync BOOL supportsMT, BOOL needsHostCursor) {}
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsyncprivate:
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync TestVMMDev mVMMDev;
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync TestDisplay mDisplay;
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync};
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsyncstatic int pdmdrvhlpAttach(PPDMDRVINS pDrvIns, uint32_t fFlags,
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync PPDMIBASE *ppBaseInterface)
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync{
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync return VERR_PDM_NO_ATTACHED_DRIVER;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync}
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsyncstatic struct PDMDRVHLPR3 pdmHlpR3 =
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync{
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync PDM_DRVHLPR3_VERSION,
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pdmdrvhlpAttach
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync};
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsyncstatic struct
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync{
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync int32_t cx;
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync int32_t cy;
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync} mouseEvent;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsyncstatic int mousePutEvent(PPDMIMOUSEPORT pInterface, int32_t iDeltaX,
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync int32_t iDeltaY, int32_t iDeltaZ, int32_t iDeltaW,
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync uint32_t fButtonStates)
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync{
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync mouseEvent.cx = iDeltaX;
6b07d9a23ed1c650aa0a3b8de9d19f51b6b67e9fvboxsync mouseEvent.cy = iDeltaY;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return VINF_SUCCESS;
d200be7337d4aad2bec2961a885e856f7866d4f6vboxsync}
d200be7337d4aad2bec2961a885e856f7866d4f6vboxsync
d200be7337d4aad2bec2961a885e856f7866d4f6vboxsyncstatic struct
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync{
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync int32_t x;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync int32_t y;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync} mouseEventAbs;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsyncstatic int mousePutEventAbs(PPDMIMOUSEPORT pInterface, uint32_t uX,
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync uint32_t uY, int32_t iDeltaZ, int32_t iDeltaW,
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync uint32_t fButtonStates)
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync{
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync mouseEventAbs.x = uX;
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync mouseEventAbs.y = uY;
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync return VINF_SUCCESS;
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync}
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsyncstatic struct PDMIMOUSEPORT pdmiMousePort =
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync{
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync mousePutEvent,
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync mousePutEventAbs
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync};
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsyncstatic void *pdmiBaseQuery(struct PDMIBASE *pInterface, const char *pszIID)
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync{
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync return &pdmiMousePort;
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync}
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsyncstatic struct PDMIBASE pdmiBase =
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync{
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync pdmiBaseQuery
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync};
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsyncstatic struct PDMDRVINS pdmdrvInsCore =
6b07d9a23ed1c650aa0a3b8de9d19f51b6b67e9fvboxsync{
6b07d9a23ed1c650aa0a3b8de9d19f51b6b67e9fvboxsync PDM_DRVINS_VERSION,
6b07d9a23ed1c650aa0a3b8de9d19f51b6b67e9fvboxsync 0,
6b07d9a23ed1c650aa0a3b8de9d19f51b6b67e9fvboxsync NIL_RTRCPTR,
6b07d9a23ed1c650aa0a3b8de9d19f51b6b67e9fvboxsync NIL_RTRCPTR,
6b07d9a23ed1c650aa0a3b8de9d19f51b6b67e9fvboxsync NIL_RTR0PTR,
6b07d9a23ed1c650aa0a3b8de9d19f51b6b67e9fvboxsync NIL_RTR0PTR,
6b07d9a23ed1c650aa0a3b8de9d19f51b6b67e9fvboxsync &pdmHlpR3,
6b07d9a23ed1c650aa0a3b8de9d19f51b6b67e9fvboxsync NULL,
6b07d9a23ed1c650aa0a3b8de9d19f51b6b67e9fvboxsync NULL,
6b07d9a23ed1c650aa0a3b8de9d19f51b6b67e9fvboxsync NULL,
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync &pdmiBase
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync};
07557d07616212d7ba6e7ab3059e85cb14633775vboxsync
07557d07616212d7ba6e7ab3059e85cb14633775vboxsyncstatic struct PDMDRVINS *ppdmdrvIns = NULL;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
529e6bec97f5ef2e005c99c205c9624583ecb7f0vboxsyncMouse *pMouse;
529e6bec97f5ef2e005c99c205c9624583ecb7f0vboxsyncConsoleMouseInterface *pConsole;
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync
e94ff1af89bf631c68367d4e291ddbb491b5e5c0vboxsyncstatic struct
529e6bec97f5ef2e005c99c205c9624583ecb7f0vboxsync{
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync int32_t x;
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync int32_t y;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync} absoluteMouse;
529e6bec97f5ef2e005c99c205c9624583ecb7f0vboxsync
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsyncstatic int setAbsoluteMouse(PPDMIVMMDEVPORT, int32_t x, int32_t y)
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync{
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync absoluteMouse.x = x;
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync absoluteMouse.y = y;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return VINF_SUCCESS;
529e6bec97f5ef2e005c99c205c9624583ecb7f0vboxsync}
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
e94ff1af89bf631c68367d4e291ddbb491b5e5c0vboxsyncstatic int updateMouseCapabilities(PPDMIVMMDEVPORT, uint32_t, uint32_t)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync{
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync return VINF_SUCCESS;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync}
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsyncvoid TestDisplay::getFramebufferDimensions(int32_t *px1, int32_t *py1,
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync int32_t *px2, int32_t *py2)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync{
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (px1)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync *px1 = -320;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (py1)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync *py1 = -240;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync if (px2)
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync *px2 = 320;
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync if (py2)
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync *py2 = 240;
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync}
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsyncint TestDisplay::getScreenResolution(uint32_t cScreen, ULONGt *pcx,
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync ULONG *pcy, ULONG *pcBPP)
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync{
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync NOREF(cScreen);
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync if (pcx)
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync *pcx = 640;
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync if (pcy)
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync *pcy = 480;
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync if (pcBPP)
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync *pcBPP = 32;
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync return S_OK;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync}
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsyncDECLEXPORT(bool) CFGMR3AreValuesValid(PCFGMNODE, const char *)
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync{
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync return true;
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync}
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
e12084fc5287a5fa65e3a28bbeb05af29c22dad7vboxsyncDECLEXPORT(int) CFGMR3QueryPtr(PCFGMNODE, const char *, void **pv)
d7dbbf62e47482dad97a2d17ae567e879b5d57b6vboxsync{
e12084fc5287a5fa65e3a28bbeb05af29c22dad7vboxsync *pv = pMouse;
9a379ef11a4bb232c8e41c12b82ec94c8e10d9a0vboxsync return VINF_SUCCESS;
e12084fc5287a5fa65e3a28bbeb05af29c22dad7vboxsync}
e12084fc5287a5fa65e3a28bbeb05af29c22dad7vboxsync
e12084fc5287a5fa65e3a28bbeb05af29c22dad7vboxsync/******************************************************************************
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync* Main test code *
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync******************************************************************************/
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsyncstatic int setup(void)
290f895ae2ac655ba90c8904a0e2687d8aa0837dvboxsync{
290f895ae2ac655ba90c8904a0e2687d8aa0837dvboxsync VMMDevPort.pfnSetAbsoluteMouse = setAbsoluteMouse;
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync VMMDevPort.pfnUpdateMouseCapabilities = updateMouseCapabilities;
e12084fc5287a5fa65e3a28bbeb05af29c22dad7vboxsync pMouse = new Mouse;
290f895ae2ac655ba90c8904a0e2687d8aa0837dvboxsync Assert(SUCCEEDED(pMouse->FinalConstruct()));
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync pConsole = new TestConsole;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync pMouse->init(pConsole);
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync ppdmdrvIns = (struct PDMDRVINS *) RTMemAllocZ( sizeof(struct PDMDRVINS)
e12084fc5287a5fa65e3a28bbeb05af29c22dad7vboxsync + Mouse::DrvReg.cbInstance);
e12084fc5287a5fa65e3a28bbeb05af29c22dad7vboxsync *ppdmdrvIns = pdmdrvInsCore;
e12084fc5287a5fa65e3a28bbeb05af29c22dad7vboxsync Mouse::DrvReg.pfnConstruct(ppdmdrvIns, NULL, 0);
e12084fc5287a5fa65e3a28bbeb05af29c22dad7vboxsync return VINF_SUCCESS;
e12084fc5287a5fa65e3a28bbeb05af29c22dad7vboxsync}
e12084fc5287a5fa65e3a28bbeb05af29c22dad7vboxsync
e12084fc5287a5fa65e3a28bbeb05af29c22dad7vboxsyncstatic void teardown(void)
e12084fc5287a5fa65e3a28bbeb05af29c22dad7vboxsync{
1f1f533d5b88c35cf740dca55c6f1937d1035a36vboxsync delete pMouse;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync delete pConsole;
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync RTMemFree(ppdmdrvIns);
290f895ae2ac655ba90c8904a0e2687d8aa0837dvboxsync}
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsyncstatic bool approxEq(int a, int b, int prec)
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync{
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync return a - b < prec && b - a < prec;
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync}
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync/** @test testAbsToVMMDevNewProtocol */
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsyncstatic void testAbsToVMMDevNewProtocol(RTTEST hTest)
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync{
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync PPDMIBASE pBase;
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync PPDMIMOUSECONNECTOR pConnector;
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync RTTestSub(hTest, "Absolute event to VMMDev, new protocol");
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync pBase = &ppdmdrvIns->IBase;
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync pConnector = (PPDMIMOUSECONNECTOR)pBase->pfnQueryInterface(pBase,
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync PDMIMOUSECONNECTOR_IID);
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync pConnector->pfnReportModes(pConnector, true, false, false);
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync pMouse->onVMMDevGuestCapsChange( VMMDEV_MOUSE_GUEST_CAN_ABSOLUTE
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync | VMMDEV_MOUSE_NEW_PROTOCOL);
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync pMouse->PutMouseEventAbsolute(0, 0, 0, 0, 0);
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync RTTESTI_CHECK_MSG(approxEq(absoluteMouse.x, 0x8000, 200),
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync ("absoluteMouse.x=%d\n", absoluteMouse.x));
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync RTTESTI_CHECK_MSG(approxEq(absoluteMouse.y, 0x8000, 200),
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync ("absoluteMouse.y=%d\n", absoluteMouse.y));
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync pMouse->PutMouseEventAbsolute(-319, -239, 0, 0, 0);
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync RTTESTI_CHECK_MSG(approxEq(absoluteMouse.x, 0, 200),
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync ("absoluteMouse.x=%d\n", absoluteMouse.x));
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync RTTESTI_CHECK_MSG(approxEq(absoluteMouse.y, 0, 200),
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync ("absoluteMouse.y=%d\n", absoluteMouse.y));
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync pMouse->PutMouseEventAbsolute(320, 240, 0, 0, 0);
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync RTTESTI_CHECK_MSG(approxEq(absoluteMouse.x, 0xffff, 200),
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync ("absoluteMouse.x=%d\n", absoluteMouse.x));
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync RTTESTI_CHECK_MSG(approxEq(absoluteMouse.y, 0xffff, 200),
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync ("absoluteMouse.y=%d\n", absoluteMouse.y));
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync RTTestSubDone(hTest);
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync}
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync/** @test testAbsToVMMDevOldProtocol */
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsyncstatic void testAbsToVMMDevOldProtocol(RTTEST hTest)
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync{
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync PPDMIBASE pBase;
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync PPDMIMOUSECONNECTOR pConnector;
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync RTTestSub(hTest, "Absolute event to VMMDev, old protocol");
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync pBase = &ppdmdrvIns->IBase;
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync pConnector = (PPDMIMOUSECONNECTOR)pBase->pfnQueryInterface(pBase,
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync PDMIMOUSECONNECTOR_IID);
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync pConnector->pfnReportModes(pConnector, true, false, false);
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync pMouse->onVMMDevGuestCapsChange(VMMDEV_MOUSE_GUEST_CAN_ABSOLUTE);
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync pMouse->PutMouseEventAbsolute(320, 240, 0, 0, 0);
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync RTTESTI_CHECK_MSG(approxEq(absoluteMouse.x, 0x8000, 200),
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync ("absoluteMouse.x=%d\n", absoluteMouse.x));
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync RTTESTI_CHECK_MSG(approxEq(absoluteMouse.y, 0x8000, 200),
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync ("absoluteMouse.y=%d\n", absoluteMouse.y));
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync pMouse->PutMouseEventAbsolute(0, 0, 0, 0, 0);
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync RTTESTI_CHECK_MSG(approxEq(absoluteMouse.x, 0, 200),
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync ("absoluteMouse.x=%d\n", absoluteMouse.x));
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync RTTESTI_CHECK_MSG(approxEq(absoluteMouse.y, 0, 200),
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync ("absoluteMouse.y=%d\n", absoluteMouse.y));
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync pMouse->PutMouseEventAbsolute(-319, -239, 0, 0, 0);
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync RTTESTI_CHECK_MSG(approxEq(absoluteMouse.x, -0x8000, 200),
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync ("absoluteMouse.x=%d\n", absoluteMouse.x));
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync RTTESTI_CHECK_MSG(approxEq(absoluteMouse.y, -0x8000, 200),
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync ("absoluteMouse.y=%d\n", absoluteMouse.y));
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync RTTestSubDone(hTest);
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync}
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync/** @test testAbsToAbsDev */
290f895ae2ac655ba90c8904a0e2687d8aa0837dvboxsyncstatic void testAbsToAbsDev(RTTEST hTest)
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync{
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync PPDMIBASE pBase;
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync PPDMIMOUSECONNECTOR pConnector;
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync RTTestSub(hTest, "Absolute event to absolute device");
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync pBase = &ppdmdrvIns->IBase;
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync pConnector = (PPDMIMOUSECONNECTOR)pBase->pfnQueryInterface(pBase,
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync PDMIMOUSECONNECTOR_IID);
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync pConnector->pfnReportModes(pConnector, false, true, false);
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync pMouse->onVMMDevGuestCapsChange( VMMDEV_MOUSE_GUEST_CAN_ABSOLUTE
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync | VMMDEV_MOUSE_NEW_PROTOCOL);
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync pMouse->PutMouseEventAbsolute(0, 0, 0, 0, 0);
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync RTTESTI_CHECK_MSG(approxEq(mouseEventAbs.x, 0x8000, 200),
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync ("mouseEventAbs.x=%d\n", mouseEventAbs.x));
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync RTTESTI_CHECK_MSG(approxEq(mouseEventAbs.y, 0x8000, 200),
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync ("mouseEventAbs.y=%d\n", mouseEventAbs.y));
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync pMouse->PutMouseEventAbsolute(-319, -239, 0, 0, 0);
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync RTTESTI_CHECK_MSG(approxEq(mouseEventAbs.x, 0, 200),
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync ("mouseEventAbs.x=%d\n", mouseEventAbs.x));
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync RTTESTI_CHECK_MSG(approxEq(mouseEventAbs.y, 0, 200),
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync ("mouseEventAbs.y=%d\n", mouseEventAbs.y));
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync pMouse->PutMouseEventAbsolute(320, 240, 0, 0, 0);
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync RTTESTI_CHECK_MSG(approxEq(mouseEventAbs.x, 0xffff, 200),
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync ("mouseEventAbs.x=%d\n", mouseEventAbs.x));
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync RTTESTI_CHECK_MSG(approxEq(mouseEventAbs.y, 0xffff, 200),
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync ("mouseEventAbs.y=%d\n", mouseEventAbs.y));
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync mouseEventAbs.x = mouseEventAbs.y = 0xffff;
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync pMouse->PutMouseEventAbsolute(-640, -480, 0, 0, 0);
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync RTTESTI_CHECK_MSG(mouseEventAbs.x = 0xffff,
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync ("mouseEventAbs.x=%d\n", mouseEventAbs.x));
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync RTTESTI_CHECK_MSG(mouseEventAbs.y == 0xffff,
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync ("mouseEventAbs.y=%d\n", mouseEventAbs.y));
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync RTTestSubDone(hTest);
ba6cd8af51db6aeff784fd6d73cadaf13ec45996vboxsync}
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync/** @todo generate this using the @test blocks above */
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsynctypedef void (*PFNTEST)(RTTEST);
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsyncstatic PFNTEST g_tests[] =
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync{
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync testAbsToVMMDevNewProtocol,
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync testAbsToVMMDevOldProtocol,
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync testAbsToAbsDev,
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync NULL
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync};
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsyncint main(void)
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync{
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync /*
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync * Init the runtime, test and say hello.
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync */
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync RTTEST hTest;
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync RTEXITCODE rcExit = RTTestInitAndCreate("tstMouseImpl", &hTest);
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync if (rcExit != RTEXITCODE_SUCCESS)
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync return rcExit;
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync RTTestBanner(hTest);
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync /*
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync * Run the tests.
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync */
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync for (unsigned i = 0; g_tests[i]; ++i)
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync {
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync AssertRC(setup());
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync g_tests[i](hTest);
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync teardown();
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync }
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync /*
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync * Summary
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync */
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync return RTTestSummaryAndDestroy(hTest);
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync}
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync
8f5b7f9f15a5da4efe1115e1be6df372cc1d1818vboxsync