tstGuestCtrlParseBuffer.cpp revision 687794577e2e35c3cae67e692a7f2130d1262a82
/* $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.
*/
#define LOG_ENABLED
#define LOG_GROUP LOG_GROUP_MAIN
#define LOG_INSTANCE NULL
#include "../include/GuestCtrlImplPrivate.h"
using namespace com;
#ifndef BYTE
#endif
typedef struct VBOXGUESTCTRL_BUFFER_VALUE
{
char *pszValue;
static struct
{
const char *pbData;
int iResult;
} aTestBlock[] =
{
/*
* Single object parsing.
* An object is represented by one or multiple key=value pairs which are
* separated by a single "\0". If this termination is missing it will be assumed
* that we need to collect more data to do a successful parsing.
*/
/* 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. */
/* Unterminated values (missing "\0"). */
{ "test4=test4\0t41", sizeof("test4=test4\0t41"), 0, sizeof("test4=test4\0") - 1, 1, VERR_MORE_DATA },
{ "test5=test5\0t51=t51", sizeof("test5=test5\0t51=t51"), 0, sizeof("test5=test5\0") - 1, 1, VERR_MORE_DATA },
/* Next block unterminated. */
{ "t51=t51\0t52=t52\0\0t53=t53", sizeof("t51=t51\0t52=t52\0\0t53=t53"), 0, sizeof("t51=t51\0t52=t52\0") - 1, 2, VINF_SUCCESS },
{ "test6=test6\0\0t61=t61", sizeof("test6=test6\0\0t61=t61"), 0, sizeof("test6=test6\0") - 1, 1, VINF_SUCCESS },
/* Good stuff. */
{ "test61=\0test611=test611\0", sizeof("test61=\0test611=test611\0"), 0, sizeof("test61=\0test611=test611\0") - 1, 2, VINF_SUCCESS },
{ "test8=test8\0t81=t81\0\0", sizeof("test8=test8\0t81=t81\0\0"), 0, sizeof("test8=test8\0t81=t81\0") - 1, 2, VINF_SUCCESS },
/* Good stuff, but with a second block -- should be *not* taken into account since
{ "t9=t9\0t91=t91\0\0t92=t92\0\0", sizeof("t9=t9\0t91=t91\0\0t92=t92\0\0"), 0, sizeof("t9=t9\0t91=t91\0") - 1, 2, VINF_SUCCESS },
/* Nasty stuff. */
/* Some "real world" examples. */
{ "hdr_id=vbt_stat\0hdr_ver=1\0name=foo.txt\0\0",
sizeof("hdr_id=vbt_stat\0hdr_ver=1\0name=foo.txt\0\0"),
0, sizeof("hdr_id=vbt_stat\0hdr_ver=1\0name=foo.txt\0") - 1,
3, VINF_SUCCESS }
};
static struct
{
const char *pbData;
/** Number of data blocks retrieved. These are separated by "\0\0". */
/** Overall result when done parsing. */
int iResult;
} aTestStream[] =
{
/* No blocks. */
/* Good stuff. */
};
int manualTest()
{
int rc;
static struct
{
const char *pbData;
int iResult;
} aTest[] =
{
{ "test5=test5\0t51=t51", sizeof("test5=test5\0t51=t51"), 0, sizeof("test5=test5\0") - 1, 1, VERR_MORE_DATA },
{ "\0\0test5=test5\0t51=t51", sizeof("\0\0test5=test5\0t51=t51"), 0, sizeof("\0\0test5=test5\0") - 1, 1, VERR_MORE_DATA },
};
unsigned iTest = 0;
{
for (;;)
{
break;
}
}
return rc;
}
int main()
{
if (rc)
return rc;
{
return RTEXITCODE_FAILURE;
}
#ifdef DEBUG_andy
rc = manualTest();
#endif
if (sizeof("sizecheck") != 10)
if (sizeof("off=rab") != 8)
if (sizeof("off=rab\0\0") != 10)
/* Don't let the assertions trigger here
* -- we rely on the return values in the test(s) below. */
RTAssertSetQuiet(true);
unsigned iTest = 0;
{
if (RT_SUCCESS(iResult))
{
{
}
{
}
else if (iResult == VERR_MORE_DATA)
{
}
if ( ( RT_SUCCESS(iResult)
|| 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)
{
/* How to properly get the current RTTESTLVL (aka IPRT_TEST_MAX_LEVEL) here?
* Hack alert: Using RTEnvGet for now. */
}
}
}
iTest = 0;
{
if (RT_SUCCESS(iResult))
{
uint32_t uNumBlocks = 0;
uint8_t uSafeCouunter = 0;
do
{
if (RT_SUCCESS(iResult))
{
/* Only count block which have at least one pair. */
uNumBlocks++;
}
if (uSafeCouunter++ > 32)
break;
} while (RT_SUCCESS(iResult));
{
}
{
}
}
else
}
/*
* Summary.
*/
return RTTestSummaryAndDestroy(hTest);
}