tstDBGCParser.cpp revision 5dd0f48aea5b772d5b217101f71606345feb8d3b
/* $Id$ */
/** @file
* DBGC Testcase - Command Parser.
*/
/*
* Copyright (C) 2006-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 "../DBGCInternal.h"
/*******************************************************************************
* Internal Functions *
*******************************************************************************/
static DECLCALLBACK(int) tstDBGCBackRead(PDBGCBACK pBack, void *pvBuf, size_t cbBuf, size_t *pcbRead);
static DECLCALLBACK(int) tstDBGCBackWrite(PDBGCBACK pBack, const void *pvBuf, size_t cbBuf, size_t *pcbWritten);
/*******************************************************************************
* Global Variables *
*******************************************************************************/
/** The test handle. */
/** The DBGC backend structure for use in this testcase. */
{
};
/** For keeping track of output prefixing. */
static bool g_fPendingPrefix = true;
/** Pointer to the current input position. */
const char *g_pszInput = NULL;
/** The output of the last command. */
static char g_szOutput[1024];
/** The current offset into g_szOutput. */
static size_t g_offOutput = 0;
/**
* Checks if there is input.
*
* @returns true if there is input ready.
* @returns false if there not input ready.
* @param pBack Pointer to the backend structure supplied by
* the backend. The backend can use this to find
* it's instance data.
* @param cMillies Number of milliseconds to wait on input data.
*/
{
return g_pszInput != NULL
&& *g_pszInput != '\0';
}
/**
* Read input.
*
* @returns VBox status code.
* @param pBack Pointer to the backend structure supplied by
* the backend. The backend can use this to find
* it's instance data.
* @param pvBuf Where to put the bytes we read.
* @param cbBuf Maximum nymber of bytes to read.
* @param pcbRead Where to store the number of bytes actually read.
* If NULL the entire buffer must be filled for a
* successful return.
*/
static DECLCALLBACK(int) tstDBGCBackRead(PDBGCBACK pBack, void *pvBuf, size_t cbBuf, size_t *pcbRead)
{
if (g_pszInput && *g_pszInput)
{
g_pszInput += cb;
}
else
*pcbRead = 0;
return VINF_SUCCESS;
}
/**
* Write (output).
*
* @returns VBox status code.
* @param pBack Pointer to the backend structure supplied by
* the backend. The backend can use this to find
* it's instance data.
* @param pvBuf What to write.
* @param cbBuf Number of bytes to write.
* @param pcbWritten Where to store the number of bytes actually written.
* If NULL the entire buffer must be successfully written.
*/
static DECLCALLBACK(int) tstDBGCBackWrite(PDBGCBACK pBack, const void *pvBuf, size_t cbBuf, size_t *pcbWritten)
{
if (pcbWritten)
*pcbWritten = cbBuf;
while (cbBuf-- > 0)
{
if (g_fPendingPrefix)
{
g_fPendingPrefix = false;
}
if (*pch == '\n')
g_fPendingPrefix = true;
/* buffer output */
{
}
/* advance */
pch++;
}
return VINF_SUCCESS;
}
/**
* Ready / busy notification.
*
* @param pBack Pointer to the backend structure supplied by
* the backend. The backend can use this to find
* it's instance data.
* @param fReady Whether it's ready (true) or busy (false).
*/
{
}
/**
* Completes the output, making sure that we're in
* the 1 position of a new line.
*/
static void tstCompleteOutput(void)
{
if (!g_fPendingPrefix)
g_fPendingPrefix = true;
}
/**
* Checks if two DBGC variables are identical
*
* @returns
* @param pVar1 .
* @param pVar2 .
*/
{
if (!pVar1)
return false;
return true;
return false;
{
case DBGCVAR_TYPE_GC_FLAT:
return false;
break;
case DBGCVAR_TYPE_GC_FAR:
return false;
return false;
break;
case DBGCVAR_TYPE_GC_PHYS:
return false;
break;
case DBGCVAR_TYPE_HC_FLAT:
return false;
break;
case DBGCVAR_TYPE_HC_PHYS:
return false;
break;
case DBGCVAR_TYPE_NUMBER:
return false;
break;
case DBGCVAR_TYPE_STRING:
case DBGCVAR_TYPE_SYMBOL:
return false;
break;
default:
AssertFailedReturn(false);
}
return false;
switch (pVar1->enmRangeType)
{
case DBGCVAR_RANGE_NONE:
break;
case DBGCVAR_RANGE_ELEMENTS:
case DBGCVAR_RANGE_BYTES:
return false;
break;
default:
AssertFailedReturn(false);
}
return true;
}
/**
* Tries one command string.
* @param pDbgc Pointer to the debugger instance.
* @param pszCmds The command to test.
* @param rcCmd The expected result.
* @param fNoExecute When set, the command is not executed.
* @param pszExpected Expected output. This does not need to include all
* of the output, just the start of it. Thus the
* prompt can be omitted.
* @param cArgs The number of expected arguments. -1 if we don't
* want to check the parsed arguments.
* @param va Info about expected parsed arguments. For each
* argument a DBGCVARTYPE, value (depends on type),
* DBGCVARRANGETYPE and optionally range value.
*/
static void tstTryExV(PDBGC pDbgc, const char *pszCmds, int rcCmd, bool fNoExecute, const char *pszExpected,
{
g_offOutput = 0;
else
else if ( !fNoExecute
&& pszExpected
if (cArgs >= 0)
{
{
switch (ExpectedArg.enmType)
{
default:
ExpectedArg.u.u64Number = 0;
break;
}
switch (ExpectedArg.enmRangeType)
{
default:
ExpectedArg.u64Range = 0;
break;
}
"Arg #%u\n"
"actual: enmType=%u u64=%#RX64 enmRangeType=%u u64Range=%#RX64\n"
"expected: enmType=%u u64=%#RX64 enmRangeType=%u u64Range=%#RX64\n",
iArg,
}
}
}
/**
* Tries one command string.
*
* @param pDbgc Pointer to the debugger instance.
* @param pszCmds The command to test.
* @param rcCmd The expected result.
* @param fNoExecute When set, the command is not executed.
* @param pszExpected Expected output. This does not need to include all
* of the output, just the start of it. Thus the
* prompt can be omitted.
* @param cArgs The number of expected arguments. -1 if we don't
* want to check the parsed arguments.
* @param ... Info about expected parsed arguments. For each
* argument a DBGCVARTYPE, value (depends on type),
* DBGCVARRANGETYPE and optionally range value.
*/
static void tstTryEx(PDBGC pDbgc, const char *pszCmds, int rcCmd, bool fNoExecute, const char *pszExpected, int32_t cArgs, ...)
{
}
/**
* Tries one command string without executing it.
*
* @param pDbgc Pointer to the debugger instance.
* @param pszCmds The command to test.
* @param rcCmd The expected result.
*/
{
}
#ifdef SOME_UNUSED_FUNCTION
/**
* Tries to execute one command string.
* @param pDbgc Pointer to the debugger instance.
* @param pszCmds The command to test.
* @param rcCmd The expected result.
* @param pszExpected Expected output. This does not need to include all
* of the output, just the start of it. Thus the
* prompt can be omitted.
*/
{
}
#endif
/**
* Test an operator on an expression resulting a plain number.
*
* @param pDbgc Pointer to the debugger instance.
* @param pszExpr The express to test.
* @param u64Expect The expected result.
*/
{
char szCmd[80];
char szExpected[80];
}
{
RTTestISub("codeview - ba");
}
int main()
{
/*
* Init.
*/
if (rc)
return rc;
/*
* Create a DBGC instance.
*/
if (RT_SUCCESS(rc))
{
if (RT_SUCCESS(rc))
{
if (RTTestErrorCount(g_hTest) == 0)
{
}
if (RTTestErrorCount(g_hTest) == 0)
{
}
/*
* Test codeview commands.
*/
#ifdef DEBUG_bird /* This will fail for a while */
if (RTTestErrorCount(g_hTest) == 0)
{
}
#endif
}
}
/*
* Summary
*/
return RTTestSummaryAndDestroy(g_hTest);
}