tstUSBProxyLinux.cpp revision d1ebd6583d0e394ed242bdf505a1e86e914baed3
/* $Id$ */
/** @file
* USBProxyServiceLinux test case.
*/
/*
* Copyright (C) 2011 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
/******************************************************************************
* Header Files *
******************************************************************************/
#include "USBProxyService.h"
#include "USBGetDevices.h"
/*** BEGIN STUBS ***/
USBProxyService::~USBProxyService() {}
void USBProxyService::removeFilter(void*) {}
void USBProxyService::serviceThreadInit() {}
void USBProxyService::serviceThreadTerm() {}
void USBProxyService::deviceAdded(ComObjPtr<HostUSBDevice> &aDevice, SessionMachinesList &llOpenedMachines, PUSBDEVICE aUSBDevice) {}
void USBProxyService::deviceChanged(ComObjPtr<HostUSBDevice> &aDevice, SessionMachinesList*, SessionMachine*) {}
bool USBProxyService::updateDeviceState(HostUSBDevice*, USBDEVICE*, bool*, SessionMachine**) { return true; }
bool USBProxyService::updateDeviceStateFake(HostUSBDevice*, USBDEVICE*, bool*, SessionMachine**) { return true; }
bool USBProxyService::isActive() { return true; }
VBoxMainHotplugWaiter::VBoxMainHotplugWaiter(char const*) {}
{
return Utf8Str();
}
int USBProxyService::getLastError(void)
{
return mLastError;
}
{
Assert(0);
}
static struct
{
const char *pcszEnvUsb;
const char *pcszEnvUsbRoot;
const char *pcszDevicesRoot;
bool fDevicesAccessible;
const char *pcszUsbfsRoot;
bool fUsbfsAccessible;
int rcMethodInit;
int rcExpected;
const char *pcszDevicesRootExpected;
bool fUsingUsbfsExpected;
} s_testEnvironment[] =
{
{ "sysfs", "/dev/bus/usb", NULL, false, NULL, false, VINF_SUCCESS, VINF_SUCCESS, "/dev/bus/usb", false },
{ "sysfs", "/dev/bus/usb", NULL, false, NULL, false, VERR_NO_MEMORY, VERR_NO_MEMORY, "/dev/bus/usb", false },
{ "sysfs", "/dev/bus/usb", "/dev/usbvbox", false, "/proc/usb/bus", false, VINF_SUCCESS, VINF_SUCCESS, "/dev/bus/usb", false },
{ "sysfs", "/dev/bus/usb", "/dev/usbvbox", false, "/proc/usb/bus", false, VERR_NO_MEMORY, VERR_NO_MEMORY, "/dev/bus/usb", false },
{ "sysfs", NULL, "/dev/vboxusb", true, NULL, false, VINF_SUCCESS, VINF_SUCCESS, "/dev/vboxusb", false },
{ "usbfs", "/dev/bus/usb", NULL, false, NULL, false, VINF_SUCCESS, VINF_SUCCESS, "/dev/bus/usb", true },
{ "usbfs", "/dev/bus/usb", NULL, false, NULL, false, VERR_NO_MEMORY, VERR_NO_MEMORY, "/dev/bus/usb", true },
{ "usbfs", "/dev/bus/usb", "/dev/usbvbox", false, "/proc/usb/bus", false, VINF_SUCCESS, VINF_SUCCESS, "/dev/bus/usb", true },
{ "usbfs", "/dev/bus/usb", "/dev/usbvbox", false, "/proc/usb/bus", false, VERR_NO_MEMORY, VERR_NO_MEMORY, "/dev/bus/usb", true },
{ "usbfs", NULL, NULL, false, "/proc/bus/usb", true, VINF_SUCCESS, VINF_SUCCESS, "/proc/bus/usb", true },
{ NULL, NULL, "/dev/vboxusb", false, "/proc/bus/usb", false, VERR_NO_MEMORY, VERR_VUSB_USB_DEVICE_PERMISSION, "", true },
{ NULL, NULL, "/dev/vboxusb", true, "/proc/bus/usb", false, VERR_NO_MEMORY, VERR_NO_MEMORY, "/dev/vboxusb", false },
{ NULL, NULL, NULL, false, "/proc/bus/usb", false, VERR_NO_MEMORY, VERR_VUSB_USBFS_PERMISSION, "", true },
{ NULL, NULL, NULL, false, "/proc/bus/usb", true, VERR_NO_MEMORY, VERR_NO_MEMORY, "/proc/bus/usb", true }
};
{
for (unsigned i = 0; i < RT_ELEMENTS(s_testEnvironment); ++i)
{
("init() returned 0x%x on line %i!\n", hrc, i));
("getLastError() returned %Rrc on line %i instead of %Rrc!\n",
("testGetDevicesRoot() returned %s on line %i instead of %s!\n",
pcszDevicesRoot, i,
("testGetUsingUsbfs() returned %RTbool on line %i instead of %RTbool!\n",
fUsingUsbfs, i,
}
}
static struct
{
const char *pacszDeviceAddresses[16];
const char *pacszAccessibleFiles[16];
const char *pcszRoot;
bool fIsDeviceNodes;
bool fAvailableExpected;
} s_testCheckDeviceRoot[] =
{
};
{
for (unsigned i = 0; i < RT_ELEMENTS(s_testCheckDeviceRoot); ++i)
{
("USBProxyLinuxCheckDeviceRoot() returned %RTbool on line %i instead of %RTbool!\n",
fAvailable, i,
}
}
int main(void)
{
/*
* Init the runtime, test and say hello.
*/
if (rcExit != RTEXITCODE_SUCCESS)
return rcExit;
/*
* Run the tests.
*/
/*
* Summary
*/
return RTTestSummaryAndDestroy(hTest);
}