tstDBGCParser.cpp revision d2b90125e86633783a62cdf31cb6fd9b01b3d35e
/* $Id$ */
/** @file
* DBGC Testcase - Command Parser.
*/
/*
* Copyright (C) 2007 knut st. osmundsen <bird-kStuff-spam@anduin.net>
*
* Oracle Corporation confidential
* All rights reserved
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#include "../DBGCInternal.h"
#include <iprt/initterm.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 *
*******************************************************************************/
/** Global error counter. */
static unsigned g_cErrors = 0;
/** 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;
/**
* 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)
{
RTPrintf("tstDBGCParser: OUTPUT: ");
g_fPendingPrefix = false;
}
if (*pch == '\n')
g_fPendingPrefix = true;
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)
RTPrintf("\n");
g_fPendingPrefix = true;
}
/**
* Tries one command string.
* @param pDbgc Pointer to the debugger instance.
* @param pszCmds The command to test.
* @param rcCmd The expected result.
*/
{
else
{
g_cErrors++;
}
}
int main()
{
/*
* Init.
*/
RTR3Init();
RTPrintf("tstDBGCParser: TESTING...\n");
/*
* Create a DBGC instance.
*/
if (RT_SUCCESS(rc))
{
if (RT_SUCCESS(rc))
{
}
}
/*
* Summary
*/
if (!g_cErrors)
RTPrintf("tstDBGCParser: SUCCESS\n");
else
return g_cErrors != 0;
}