Changeset 26848 in vbox
- Timestamp:
- Feb 26, 2010 1:22:09 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/testcase/tstRTSystemQueryOsInfo.cpp
r26605 r26848 33 33 *******************************************************************************/ 34 34 #include <iprt/system.h> 35 36 #include <iprt/assert.h> 35 37 #include <iprt/string.h> 36 38 #include <iprt/test.h> … … 54 56 * Simple stuff. 55 57 */ 56 char szInfo[ 256];58 char szInfo[_4K]; 57 59 58 60 rc = RTSystemQueryOSInfo(RTSYSOSINFO_PRODUCT, szInfo, sizeof(szInfo)); … … 87 89 * Check buffer overflow 88 90 */ 89 for (int i = RTSYSOSINFO_INVALID + 1; i < RTSYSOSINFO_END; i++) 91 RTAssertSetQuiet(true); 92 RTAssertSetMayPanic(false); 93 for (int i = RTSYSDMISTR_INVALID + 1; i < RTSYSDMISTR_END; i++) 90 94 { 91 rc = VERR_BUFFER_OVERFLOW; 92 for (size_t cch = 0; cch < sizeof(szInfo) && rc == VERR_BUFFER_OVERFLOW; cch++) 95 RTTESTI_CHECK_RC(RTSystemQueryDmiString((RTSYSDMISTR)i, szInfo, 0), VERR_INVALID_PARAMETER); 96 97 /* Get the length of the info and check that we get overflow errors for 98 everything less that it. */ 99 rc = RTSystemQueryOSInfo((RTSYSOSINFO)i, szInfo, sizeof(szInfo)); 100 if (RT_FAILURE(rc)) 101 continue; 102 size_t const cchInfo = strlen(szInfo); 103 104 for (size_t cch = 1; cch < sizeof(szInfo) && cch < cchInfo; cch++) 93 105 { 94 106 memset(szInfo, 0x7f, sizeof(szInfo)); 95 rc = RTSystemQueryOSInfo((RTSYSOSINFO)i, szInfo, cch);107 RTTESTI_CHECK_RC(RTSystemQueryOSInfo((RTSYSOSINFO)i, szInfo, cch), VERR_BUFFER_OVERFLOW); 96 108 97 109 /* check the padding. */ … … 104 116 105 117 /* check for zero terminator. */ 106 if ( ( rc == VERR_BUFFER_OVERFLOW 107 || rc == VERR_NOT_SUPPORTED 108 || RT_SUCCESS(rc)) 109 && cch > 0 110 && !memchr(szInfo, '\0', cch)) 111 { 118 if (!memchr(szInfo, '\0', cch)) 119 RTTestIFailed("level=%d, rc=%Rrc, cch=%zu: Buffer not terminated!\n", i, rc, cch); 120 } 112 121 113 RTTestIFailed("level=%d, rc=%Rrc, cch=%zu: Buffer not terminated!\n", i, rc, cch);114 g_cErrors++;115 }116 }122 /* Check that the exact length works. */ 123 rc = RTSystemQueryOSInfo((RTSYSOSINFO)i, szInfo, cchInfo + 1); 124 if (rc != VINF_SUCCESS) 125 RTTestIFailed("level=%d: rc=%Rrc when specifying exactly right buffer length (%zu)\n", i, rc, cchInfo + 1); 117 126 } 118 127
Note:
See TracChangeset
for help on using the changeset viewer.