VirtualBox

source: vbox/trunk/src/VBox/Debugger/testcase/tstDBGCParser.cpp@ 5685

Last change on this file since 5685 was 5685, checked in by vboxsync, 17 years ago

testcase framework.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 5.0 KB
Line 
1/* $Id: tstDBGCParser.cpp 5685 2007-11-11 11:11:40Z vboxsync $ */
2/** @file
3 * DBGC Testcase - Command Parser.
4 */
5
6/*
7 * Copyright (c) 2007 knut st. osmundsen <[email protected]>
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License as published by the Free Software Foundation,
13 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
14 * distribution. VirtualBox OSE is distributed in the hope that it will
15 * be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 */
18
19/*******************************************************************************
20* Header Files *
21*******************************************************************************/
22#include <VBox/dbg.h>
23#include "../DBGCInternal.h"
24
25#include <iprt/stream.h>
26#include <iprt/string.h>
27#include <iprt/initterm.h>
28
29
30/*******************************************************************************
31* Internal Functions *
32*******************************************************************************/
33static DECLCALLBACK(bool) tstDBGCBackInput(PDBGCBACK pBack, uint32_t cMillies);
34static DECLCALLBACK(int) tstDBGCBackRead(PDBGCBACK pBack, void *pvBuf, size_t cbBuf, size_t *pcbRead);
35static DECLCALLBACK(int) tstDBGCBackWrite(PDBGCBACK pBack, const void *pvBuf, size_t cbBuf, size_t *pcbWritten);
36
37
38/*******************************************************************************
39* Global Variables *
40*******************************************************************************/
41/** Global error counter. */
42static unsigned g_cErrors = 0;
43/** The DBGC backend structure for use in this testcase. */
44static DBGCBACK g_tstBack =
45{
46 tstDBGCBackInput,
47 tstDBGCBackRead,
48 tstDBGCBackWrite
49};
50/** For keeping track of output prefixing. */
51static bool g_fPendingPrefix = true;
52
53
54/**
55 * Checks if there is input.
56 *
57 * @returns true if there is input ready.
58 * @returns false if there not input ready.
59 * @param pBack Pointer to the backend structure supplied by
60 * the backend. The backend can use this to find
61 * it's instance data.
62 * @param cMillies Number of milliseconds to wait on input data.
63 */
64static DECLCALLBACK(bool) tstDBGCBackInput(PDBGCBACK pBack, uint32_t cMillies)
65{
66 RTPrintf("tstDBGCParser: tstDBGCBackInput was called!\n");
67 g_cErrors++;
68 return false;
69}
70
71
72/**
73 * Read input.
74 *
75 * @returns VBox status code.
76 * @param pBack Pointer to the backend structure supplied by
77 * the backend. The backend can use this to find
78 * it's instance data.
79 * @param pvBuf Where to put the bytes we read.
80 * @param cbBuf Maximum nymber of bytes to read.
81 * @param pcbRead Where to store the number of bytes actually read.
82 * If NULL the entire buffer must be filled for a
83 * successful return.
84 */
85static DECLCALLBACK(int) tstDBGCBackRead(PDBGCBACK pBack, void *pvBuf, size_t cbBuf, size_t *pcbRead)
86{
87 RTPrintf("tstDBGCParser: tstDBGCBackRead was called!\n");
88 g_cErrors++;
89 return VERR_INTERNAL_ERROR;
90}
91
92
93/**
94 * Write (output).
95 *
96 * @returns VBox status code.
97 * @param pBack Pointer to the backend structure supplied by
98 * the backend. The backend can use this to find
99 * it's instance data.
100 * @param pvBuf What to write.
101 * @param cbBuf Number of bytes to write.
102 * @param pcbWritten Where to store the number of bytes actually written.
103 * If NULL the entire buffer must be successfully written.
104 */
105static DECLCALLBACK(int) tstDBGCBackWrite(PDBGCBACK pBack, const void *pvBuf, size_t cbBuf, size_t *pcbWritten)
106{
107 const char *pch = (const char *)pvBuf;
108 *pcbWritten = cbBuf;
109 while (cbBuf-- > 0)
110 {
111 if (g_fPendingPrefix)
112 {
113 RTPrintf("tstDBGCParser: OUTPUT: ");
114 g_fPendingPrefix = false;
115 }
116 if (*pch == '\n')
117 g_fPendingPrefix = true;
118 RTPrintf("%c", *pch);
119 pch++;
120 }
121 return VINF_SUCCESS;
122}
123
124
125/**
126 * Completes the output, making sure that we're in
127 * the 1 position of a new line.
128 */
129static void tstCompleteOutput(void)
130{
131 if (!g_fPendingPrefix)
132 RTPrintf("\n");
133 g_fPendingPrefix = true;
134}
135
136
137
138
139int main()
140{
141 /*
142 * Init.
143 */
144 RTR3Init();
145 RTPrintf("tstDBGCParser: TESTING...\n");
146
147 /*
148 * Create a DBGC instance.
149 */
150 PDBGC pDbgc;
151 int rc = dbgcCreate(&pDbgc, &g_tstBack, 0);
152 if (RT_SUCCESS(rc))
153 {
154
155 dbgcDestroy(pDbgc);
156 }
157
158
159 /*
160 * Summary
161 */
162 if (!g_cErrors)
163 RTPrintf("tstDBGCParser: SUCCESS\n");
164 else
165 RTPrintf("tstDBGCParser: FAILURE - %d errors\n", g_cErrors);
166 return g_cErrors != 0;
167}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette