VirtualBox

source: vbox/trunk/src/VBox/VMM/testcase/tstCFGM.cpp@ 4787

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

Biggest check-in ever. New source code headers for all (C) innotek files.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 4.2 KB
Line 
1/* $Id: tstCFGM.cpp 4071 2007-08-07 17:07:59Z vboxsync $ */
2/** @file
3 * Testcase for CFGM.
4 */
5
6/*
7 * Copyright (C) 2006-2007 innotek GmbH
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/*******************************************************************************
21* Header Files *
22*******************************************************************************/
23#include <VBox/sup.h>
24#include <VBox/cfgm.h>
25#include <VBox/mm.h>
26#include <VBox/vm.h>
27
28#include <VBox/err.h>
29#include <VBox/param.h>
30#include <iprt/runtime.h>
31#include <iprt/stream.h>
32#include <iprt/string.h>
33
34
35int main()
36{
37 /*
38 * Init runtime.
39 */
40 RTR3Init();
41
42 /*
43 * Create empty VM structure and init SSM.
44 */
45 PVM pVM;
46 int rc = SUPInit(NULL);
47 if (VBOX_SUCCESS(rc))
48 rc = SUPPageAlloc((sizeof(*pVM) + PAGE_SIZE - 1) >> PAGE_SHIFT, (void **)&pVM);
49 if (VBOX_FAILURE(rc))
50 {
51 RTPrintf("Fatal error: SUP Failure! rc=%Vrc\n", rc);
52 return 1;
53 }
54
55 rc = STAMR3Init(pVM);
56 if (VBOX_FAILURE(rc))
57 {
58 RTPrintf("FAILURE: STAMR3Init failed. rc=%Vrc\n", rc);
59 return 1;
60 }
61
62 rc = CFGMR3Init(pVM, NULL, NULL);
63 if (VBOX_FAILURE(rc))
64 {
65 RTPrintf("FAILURE: CFGMR3Init failed. rc=%Vrc\n", rc);
66 return 1;
67 }
68
69 if (!CFGMR3GetRoot(pVM))
70 {
71 RTPrintf("FAILURE: CFGMR3GetRoot failed\n");
72 return 1;
73 }
74
75 /* integer */
76 uint64_t u64;
77 rc = CFGMR3QueryU64(CFGMR3GetRoot(pVM), "RamSize", &u64);
78 if (VBOX_FAILURE(rc))
79 {
80 RTPrintf("FAILURE: CFGMR3QueryU64(,\"RamSize\",) failed. rc=%Vrc\n", rc);
81 return 1;
82 }
83
84 size_t cb;
85 rc = CFGMR3QuerySize(CFGMR3GetRoot(pVM), "RamSize", &cb);
86 if (VBOX_FAILURE(rc))
87 {
88 RTPrintf("FAILURE: CFGMR3QuerySize(,\"RamSize\",) failed. rc=%Vrc\n", rc);
89 return 1;
90 }
91 if (cb != sizeof(uint64_t))
92 {
93 RTPrintf("FAILURE: Incorrect valuesize %d for \"RamSize\" value.\n", cb);
94 return 1;
95 }
96
97 /* string */
98 char *pszName = NULL;
99 rc = CFGMR3QueryStringAlloc(CFGMR3GetRoot(pVM), "Name", &pszName);
100 if (VBOX_FAILURE(rc))
101 {
102 RTPrintf("FAILURE: CFGMR3QueryStringAlloc(,\"Name\" failed. rc=%Vrc\n", rc);
103 return 1;
104 }
105
106 rc = CFGMR3QuerySize(CFGMR3GetRoot(pVM), "Name", &cb);
107 if (VBOX_FAILURE(rc))
108 {
109 RTPrintf("FAILURE: CFGMR3QuerySize(,\"RamSize\",) failed. rc=%Vrc\n", rc);
110 return 1;
111 }
112 if (cb != strlen(pszName) + 1)
113 {
114 RTPrintf("FAILURE: Incorrect valuesize %d for \"Name\" value '%s'.\n", cb, pszName);
115 return 1;
116 }
117 MMR3HeapFree(pszName);
118
119
120 /* test multilevel node creation */
121 PCFGMNODE pChild = NULL;
122 rc = CFGMR3InsertNode(CFGMR3GetRoot(pVM), "First/Second/Third//Final", &pChild);
123 if (VBOX_FAILURE(rc))
124 {
125 RTPrintf("FAILURE: CFGMR3InsertNode(,\"First/Second/Third//Final\" failed. rc=%Vrc\n", rc);
126 return 1;
127 }
128 rc = CFGMR3InsertInteger(pChild, "BoolValue", 1);
129 if (VBOX_FAILURE(rc))
130 {
131 RTPrintf("FAILURE: CFGMR3InsertInteger(,\"BoolValue\", 1) failed. rc=%Vrc\n", rc);
132 return 1;
133 }
134 PCFGMNODE pNode = CFGMR3GetChild(CFGMR3GetRoot(pVM), "First/Second/Third/Final");
135 if (pNode != pChild)
136 {
137 RTPrintf("FAILURE: CFGMR3GetChild(,\"First/Second/Third/Final/BoolValue\") failed. pNode=%p expected %p\n", pNode, pChild);
138 return 1;
139 }
140 bool f = false;
141 rc = CFGMR3QueryBool(pNode, "BoolValue", &f);
142 if (VBOX_FAILURE(rc) || !f)
143 {
144 RTPrintf("FAILURE: CFGMR3QueryBool(,\"BoolValue\",) failed. rc=%Vrc f=%d\n", rc, f);
145 return 1;
146 }
147
148
149 /* done */
150 rc = CFGMR3Term(pVM);
151 if (VBOX_FAILURE(rc))
152 {
153 RTPrintf("FAILURE: CFGMR3QueryU64(,\"RamSize\" failed. rc=%Vrc\n", rc);
154 return 1;
155 }
156
157 RTPrintf("tstCFGM: SUCCESS\n");
158 return rc;
159}
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