3
* Simple VBox HDD container test utility. Only fast tests.
7
* Copyright (C) 2006-2007 Oracle Corporation
9
* This file is part of VirtualBox Open Source Edition (OSE), as
10
* available from http://www.virtualbox.org. This file is free software;
11
* you can redistribute it and/or modify it under the terms of the GNU
12
* General Public License (GPL) as published by the Free Software
13
* Foundation, in version 2 as it comes in the "COPYING" file of the
14
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
19
#include <VBox/VBoxHDD.h>
20
#include <iprt/string.h>
21
#include <iprt/stream.h>
22
#include <iprt/file.h>
24
#include <iprt/initterm.h>
25
#include <iprt/rand.h>
29
/*******************************************************************************
31
*******************************************************************************/
32
/** The error count. */
33
unsigned g_cErrors = 0;
35
static struct KeyValuePair {
39
{ "TargetName", "test" },
41
{ "TargetAddress", "address" },
45
static bool tstAreKeysValid(void *pvUser, const char *pszzValid)
50
static const char *tstGetValueByKey(const char *pszKey)
52
for (int i = 0; aCfgNode[i].key; i++)
53
if (!strcmp(aCfgNode[i].key, pszKey))
54
return aCfgNode[i].value;
58
static int tstQuerySize(void *pvUser, const char *pszName, size_t *pcbValue)
60
const char *pszValue = tstGetValueByKey(pszName);
62
return VERR_CFGM_VALUE_NOT_FOUND;
63
*pcbValue = strlen(pszValue) + 1;
67
static int tstQuery(void *pvUser, const char *pszName, char *pszValue, size_t cchValue)
69
const char *pszTmp = tstGetValueByKey(pszName);
71
return VERR_CFGM_VALUE_NOT_FOUND;
72
size_t cchTmp = strlen(pszTmp) + 1;
73
if (cchValue < cchTmp)
74
return VERR_CFGM_NOT_ENOUGH_SPACE;
75
memcpy(pszValue, pszTmp, cchTmp);
80
VDINTERFACECONFIG icc = {
81
sizeof(VDINTERFACECONFIG),
82
VDINTERFACETYPE_CONFIG,
88
static int tstVDBackendInfo(void)
91
#define MAX_BACKENDS 100
92
VDBACKENDINFO aVDInfo[MAX_BACKENDS];
98
RTPrintf("%s rc=%Rrc\n", str, rc); \
103
rc = VDBackendInfo(MAX_BACKENDS, aVDInfo, &cEntries);
104
CHECK("VDBackendInfo()");
106
for (unsigned i=0; i < cEntries; i++)
108
RTPrintf("Backend %u: name=%s capabilities=%#06x extensions=",
109
i, aVDInfo[i].pszBackend, aVDInfo[i].uBackendCaps);
110
if (aVDInfo[i].papszFileExtensions)
112
const char *const *papsz = aVDInfo[i].papszFileExtensions;
113
while (*papsz != NULL)
115
if (papsz != aVDInfo[i].papszFileExtensions)
117
RTPrintf("%s", *papsz);
120
if (papsz == aVDInfo[i].papszFileExtensions)
125
RTPrintf(" config=");
126
if (aVDInfo[i].paConfigInfo)
128
PCVDCONFIGINFO pa = aVDInfo[i].paConfigInfo;
129
while (pa->pszKey != NULL)
131
if (pa != aVDInfo[i].paConfigInfo)
133
RTPrintf("(key=%s type=", pa->pszKey);
134
switch (pa->enmValueType)
136
case VDCFGVALUETYPE_INTEGER:
139
case VDCFGVALUETYPE_STRING:
142
case VDCFGVALUETYPE_BYTES:
146
RTPrintf("INVALID!");
148
RTPrintf(" default=");
149
if (pa->pszDefaultValue)
150
RTPrintf("%s", pa->pszDefaultValue);
157
if (pa->uKeyFlags & VD_CFGKEY_MANDATORY)
161
RTPrintf("mandatory");
164
if (pa->uKeyFlags & VD_CFGKEY_EXPERT)
174
if (pa == aVDInfo[i].paConfigInfo)
182
ic.cbSize = sizeof(ic);
183
ic.enmInterface = VDINTERFACETYPE_CONFIG;
184
ic.pCallbacks = &icc;
185
char *pszLocation, *pszName;
186
rc = aVDInfo[i].pfnComposeLocation(&ic, &pszLocation);
187
CHECK("pfnComposeLocation()");
190
RTMemFree(pszLocation);
191
if (aVDInfo[i].uBackendCaps & VD_CAP_FILE)
193
RTPrintf("Non-NULL location returned for file-based backend!\n");
194
return VERR_INTERNAL_ERROR;
197
rc = aVDInfo[i].pfnComposeName(&ic, &pszName);
198
CHECK("pfnComposeName()");
202
if (aVDInfo[i].uBackendCaps & VD_CAP_FILE)
204
RTPrintf("Non-NULL name returned for file-based backend!\n");
205
return VERR_INTERNAL_ERROR;
215
int main(int argc, char *argv[])
220
RTPrintf("tstVD-2: TESTING...\n");
222
rc = tstVDBackendInfo();
225
RTPrintf("tstVD-2: getting backend info test failed! rc=%Rrc\n", rc);
232
RTPrintf("tstVD-2: unloading backends failed! rc=%Rrc\n", rc);
239
RTPrintf("tstVD-2: SUCCESS\n");
241
RTPrintf("tstVD-2: FAILURE - %d errors\n", g_cErrors);