tstGuestCtrlParseBuffer.cpp revision c089168ef1a0fde89a6501905daef3f37a153512
/* $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 <stdio.h>
#include <stdlib.h>
#include "../include/GuestCtrlImplPrivate.h"
using namespace com;
#define LOG_ENABLED
#define LOG_GROUP LOG_GROUP_MAIN
#define LOG_INSTANCE NULL
#ifndef BYTE
#endif
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 },
/* Empty buffers. */
/* 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). */
{ "\0\0\0\0off=rab\0zab=oob\0\0", sizeof("\0\0\0\0off=rab\0zab=oob\0\0"), 0, 1, 0, VERR_MORE_DATA },
};
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 main()
{
if (rc)
return rc;
{
RTPrintf("ERROR: failed to initialize COM!\n");
return rc;
}
if (sizeof("sizecheck") != 10)
if (sizeof("off=rab") != 8)
if (sizeof("off=rab\0\0") != 10)
unsigned iTest = 0;
{
if (RT_SUCCESS(iResult))
{
{
}
{
}
{
}
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 (uToWrite)
{
}
}
}
}
{
if (RT_SUCCESS(iResult))
{
uint32_t uNumBlocks = 0;
do
{
if ( iResult == VINF_SUCCESS
|| iResult == VERR_MORE_DATA)
{
/* Only count block which have at least one pair. */
if (stream.GetNumPairs())
{
uNumBlocks++;
stream.ClearPairs();
}
}
if (uNumBlocks > 32)
break; /* Give up if unreasonable big. */
} while (iResult == VERR_MORE_DATA);
{
}
{
}
}
else
}
/*
* Summary.
*/
return RTTestSummaryAndDestroy(hTest);
}