tstGuestCtrlParseBuffer.cpp revision 99ca608baa061219892d090d8d68b013ef73e7c3
/* $Id$ */
/** @file
*
* Output stream parsing test cases.
*/
/*
* 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.
*/
#include <map>
#ifndef BYTE
#endif
/** @todo Use original source of GuestCtrlImpl.cpp! */
typedef struct VBOXGUESTCTRL_BUFFER_VALUE
{
char *pszValue;
static struct
{
const char *pbData;
int iResult;
} aTests[] =
{
/* Invalid stuff. */
{ NULL, 0, 0, 0, 0, VERR_INVALID_POINTER },
{ "", 0, 0, 0, 0, VERR_INVALID_PARAMETER },
{ "", 0, 0, 0, 0, VERR_INVALID_PARAMETER },
{ "foo=bar1", 0, 0, 0, 0, VERR_INVALID_PARAMETER },
/* Incomplete buffer (missing \0 termination). */
/* Incomplete buffer (missing components). */
/* Last sequence is incomplete -- new offset should point to it. */
{ "boo=hoo\0baz=boo\0qwer", sizeof("boo=hoo\0baz=boo\0qwer"), 0, sizeof("boo=hoo\0baz=boo"), 2, VERR_MORE_DATA },
/* Parsing good stuff. */
/* Parsing until a different block (two terminations, returning offset to next block). */
};
static struct
{
const char *pbData;
/** Number of data blocks retrieved. These are separated by "\0\0". */
/** Overall result when done parsing. */
int iResult;
} aTests2[] =
{
{ "\0\0\0soo=foo\0goo=loo\0\0zab=oob", sizeof("\0\0\0soo=foo\0goo=loo\0\0zab=oob"), 2, VINF_SUCCESS },
};
int outputBufferParse(const BYTE *pbData, size_t cbData, uint32_t *puOffset, GuestBufferMap& mapBuf)
{
int rc = VINF_SUCCESS;
{
/* Search and of current pair (key=value\0). */
{
if (*pszEnd == '\0')
break;
pszEnd++;
}
if ( *pszEnd != '\0'
|| !uPairLen)
{
rc = VERR_MORE_DATA;
break;
}
while ( *pszSep != '='
{
pszSep++;
}
{
rc = VERR_MORE_DATA;
break;
}
/* Get key (if present). */
if (uKeyLen)
{
if (!pszKey)
{
rc = VERR_NO_MEMORY;
break;
}
/* Get value (if present). */
if (uValLen)
{
if (!pszVal)
{
rc = VERR_NO_MEMORY;
break;
}
}
}
}
return rc;
}
{
{
}
}
int main()
{
if (rc)
return rc;
if (sizeof("sizecheck") != 10)
{
{
}
{
}
{
}
else if (iResult == VERR_MORE_DATA)
{
/* There is remaining data left in the buffer (which needs to be merged
* with a following buffer) -- print it. */
if (pszRemaining && uOffsetNew)
{
}
}
}
{
int iResult;
uint32_t uNumBlocks = 0;
{
if ( iResult == VINF_SUCCESS
|| iResult == VERR_MORE_DATA)
{
uNumBlocks++;
uOffset++;
}
else
break;
if (uNumBlocks > 32)
break; /* Give up if unreasonable big. */
}
{
}
}
/*
* Summary.
*/
return RTTestSummaryAndDestroy(hTest);
}