VirtualBox

source: vbox/trunk/src/VBox/Runtime/testcase/tstRTSystemQueryDmi.cpp@ 26608

Last change on this file since 26608 was 26608, checked in by vboxsync, 15 years ago

IPRT: linux implementation of RTSystemQueryDmiString.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.3 KB
Line 
1/* $Id: tstRTSystemQueryDmi.cpp 26608 2010-02-17 12:48:33Z vboxsync $ */
2/** @file
3 * IPRT Testcase - RTSystemQueryDmi*.
4 */
5
6/*
7 * Copyright (C) 2006-2010 Sun Microsystems, Inc.
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 (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 *
26 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
27 * Clara, CA 95054 USA or visit http://www.sun.com if you need
28 * additional information or have any questions.
29 */
30
31/*******************************************************************************
32* Header Files *
33*******************************************************************************/
34#include <iprt/system.h>
35
36#include <iprt/assert.h>
37#include <iprt/string.h>
38#include <iprt/test.h>
39
40
41int main()
42{
43 RTTEST hTest;
44 int rc = RTTestInitAndCreate("tstRTSystemQueryDmi", &hTest);
45 if (rc)
46 return rc;
47 RTTestBanner(hTest);
48
49 /*
50 * Simple stuff.
51 */
52 char szInfo[256];
53
54 rc = RTSystemQueryDmiString(RTSYSDMISTR_PRODUCT_NAME, szInfo, sizeof(szInfo));
55 RTTestIPrintf(RTTESTLVL_ALWAYS, "PRODUCT_NAME: \"%s\", rc=%Rrc\n", szInfo, rc);
56
57 rc = RTSystemQueryDmiString(RTSYSDMISTR_PRODUCT_VERSION, szInfo, sizeof(szInfo));
58 RTTestIPrintf(RTTESTLVL_ALWAYS, "PRODUCT_VERSION: \"%s\", rc=%Rrc\n", szInfo, rc);
59
60 rc = RTSystemQueryDmiString(RTSYSDMISTR_PRODUCT_UUID, szInfo, sizeof(szInfo));
61 RTTestIPrintf(RTTESTLVL_ALWAYS, "PRODUCT_UUID: \"%s\", rc=%Rrc\n", szInfo, rc);
62
63 rc = RTSystemQueryDmiString(RTSYSDMISTR_PRODUCT_SERIAL, szInfo, sizeof(szInfo));
64 RTTestIPrintf(RTTESTLVL_ALWAYS, "PRODUCT_SERIAL: \"%s\", rc=%Rrc\n", szInfo, rc);
65
66 /*
67 * Check that unsupported stuff is terminated correctly.
68 */
69 for (int i = RTSYSDMISTR_INVALID + 1; i < RTSYSDMISTR_END; i++)
70 {
71 memset(szInfo, ' ', sizeof(szInfo));
72 rc = RTSystemQueryDmiString((RTSYSDMISTR)i, szInfo, sizeof(szInfo));
73 if ( rc == VERR_NOT_SUPPORTED
74 && szInfo[0] != '\0')
75 RTTestIFailed("level=%d; unterminated buffer on VERR_NOT_SUPPORTED\n", i);
76 else if (RT_SUCCESS(rc) || rc == VERR_BUFFER_OVERFLOW || rc == VERR_ACCESS_DENIED)
77 RTTESTI_CHECK(memchr(szInfo, '\0', sizeof(szInfo)) != NULL);
78 else if (rc != VERR_NOT_SUPPORTED)
79 RTTestIFailed("level=%d unexpected rc=%Rrc\n", i, rc);
80 }
81
82 /*
83 * Check buffer overflow
84 */
85 RTAssertSetQuiet(true);
86 RTAssertSetMayPanic(false);
87 for (int i = RTSYSDMISTR_INVALID + 1; i < RTSYSDMISTR_END; i++)
88 {
89 rc = VERR_BUFFER_OVERFLOW;
90 for (size_t cch = 0; cch < sizeof(szInfo) && rc == VERR_BUFFER_OVERFLOW; cch++)
91 {
92 memset(szInfo, 0x7f, sizeof(szInfo));
93 rc = RTSystemQueryDmiString((RTSYSDMISTR)i, szInfo, cch);
94
95 /* check the padding. */
96 for (size_t off = cch; off < sizeof(szInfo); off++)
97 if (szInfo[off] != 0x7f)
98 {
99 RTTestIFailed("level=%d, rc=%Rrc, cch=%zu, off=%zu: Wrote too much!\n", i, rc, cch, off);
100 break;
101 }
102
103 /* check for zero terminator. */
104 if ( ( rc == VERR_BUFFER_OVERFLOW
105 || rc == VERR_NOT_SUPPORTED
106 || RT_SUCCESS(rc))
107 && cch > 0
108 && !memchr(szInfo, '\0', cch))
109 RTTestIFailed("level=%d, rc=%Rrc, cch=%zu: Buffer not terminated!\n", i, rc, cch);
110 }
111 }
112
113 return RTTestSummaryAndDestroy(hTest);
114}
115
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