Changeset 19205 in vbox
- Timestamp:
- Apr 27, 2009 10:03:40 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/testcase/tstUuid.cpp
r13837 r19205 34 34 *******************************************************************************/ 35 35 #include <iprt/uuid.h> 36 #include <iprt/test.h> 36 37 #include <iprt/stream.h> 37 38 #include <iprt/err.h> … … 43 44 { 44 45 int rc; 45 int cErrors = 0; 46 47 rc = RTR3Init(); 48 if (rc) 46 RTTEST hTest; 47 if ( RT_FAILURE(rc = RTR3Init()) 48 || RT_FAILURE(rc = RTTestCreate("tstUuid", &hTest))) 49 49 { 50 RTPrintf(" RTR3Initfailed: %Rrc\n", rc);50 RTPrintf("tstUuid: RTR3Init or RTTestCreate failed: %Rrc\n", rc); 51 51 return 1; 52 52 } 53 54 #define CHECK_RC() \ 55 do { if (RT_FAILURE(rc)) { RTPrintf("tstUuid(%d): rc=%Rrc!\n", __LINE__, rc); cErrors++; } } while (0) 56 #define CHECK_EXPR(expr) \ 57 do { const bool f = !!(expr); if (!f) { RTPrintf("tstUuid(%d): %s!\n", __LINE__, #expr); cErrors++; } } while (0) 58 53 RTTestBanner(hTest); 54 55 56 #define CHECK_RC() \ 57 do { if (RT_FAILURE(rc)) { RTTestFailed(hTest, "line %d: rc=%Rrc", __LINE__, rc); } } while (0) 58 59 RTTestSub(hTest, "RTUuidClear & RTUuisIsNull"); 59 60 RTUUID UuidNull; 60 61 rc = RTUuidClear(&UuidNull); CHECK_RC(); 61 CHECK_EXPR(RTUuidIsNull(&UuidNull)); 62 CHECK_EXPR(RTUuidCompare(&UuidNull, &UuidNull) == 0); 63 62 63 RTTEST_CHECK(hTest, RTUuidIsNull(&UuidNull)); 64 RTTEST_CHECK(hTest, RTUuidCompare(&UuidNull, &UuidNull) == 0); 65 66 RTTestSub(hTest, "RTUuidCreate"); 64 67 RTUUID Uuid; 65 68 rc = RTUuidCreate(&Uuid); CHECK_RC(); 66 CHECK_EXPR(!RTUuidIsNull(&Uuid)); 67 CHECK_EXPR(RTUuidCompare(&Uuid, &Uuid) == 0); 68 CHECK_EXPR(RTUuidCompare(&Uuid, &UuidNull) > 0); 69 CHECK_EXPR(RTUuidCompare(&UuidNull, &Uuid) < 0); 70 69 RTTEST_CHECK(hTest, !RTUuidIsNull(&Uuid)); 70 RTTEST_CHECK(hTest, RTUuidCompare(&Uuid, &Uuid) == 0); 71 RTTEST_CHECK(hTest, RTUuidCompare(&Uuid, &UuidNull) > 0); 72 RTTEST_CHECK(hTest, RTUuidCompare(&UuidNull, &Uuid) < 0); 73 74 RTTestSub(hTest, "RTUuidToStr"); 71 75 char sz[RTUUID_STR_LENGTH]; 72 76 rc = RTUuidToStr(&Uuid, sz, sizeof(sz)); CHECK_RC(); 77 RTTEST_CHECK(hTest, strlen(sz) == RTUUID_STR_LENGTH - 1); 78 RTTestPrintf(hTest, RTTESTLVL_INFO, "UUID=%s\n", sz); 79 80 RTTestSub(hTest, "RTUuidFromStr"); 73 81 RTUUID Uuid2; 74 82 rc = RTUuidFromStr(&Uuid2, sz); CHECK_RC(); 75 CHECK_EXPR(RTUuidCompare(&Uuid, &Uuid2) == 0); 76 77 RTPrintf("tstUuid: Created {%s}\n", sz); 83 RTTEST_CHECK(hTest, RTUuidCompare(&Uuid, &Uuid2) == 0); 84 85 RTTestSub(hTest, "RTUuidToUtf16"); 86 RTUTF16 wsz[RTUUID_STR_LENGTH]; 87 rc = RTUuidToUtf16(&Uuid, wsz, sizeof(wsz)); CHECK_RC(); 88 RTTEST_CHECK(hTest, RTUtf16Len(wsz) == RTUUID_STR_LENGTH - 1); 89 90 RTTestSub(hTest, "RTUuidFromUtf16"); 91 rc = RTUuidFromUtf16(&Uuid2, wsz); CHECK_RC(); 92 RTTEST_CHECK(hTest, RTUuidCompare(&Uuid, &Uuid2) == 0); 93 78 94 79 95 /* 80 96 * Check the binary representation. 81 97 */ 98 RTTestSub(hTest, "Binary representation"); 82 99 RTUUID Uuid3; 83 100 Uuid3.au8[0] = 0x01; … … 101 118 const char *pszUuid3 = "67452301-ab89-4fcd-90b2-547698badcfe"; 102 119 rc = RTUuidToStr(&Uuid3, sz, sizeof(sz)); CHECK_RC(); 103 CHECK_EXPR(strcmp(sz, pszUuid3) == 0);120 RTTEST_CHECK(hTest, strcmp(sz, pszUuid3) == 0); 104 121 rc = RTUuidFromStr(&Uuid, pszUuid3); CHECK_RC(); 105 CHECK_EXPR(RTUuidCompare(&Uuid, &Uuid3) == 0);106 CHECK_EXPR(memcmp(&Uuid3, &Uuid, sizeof(Uuid)) == 0);122 RTTEST_CHECK(hTest, RTUuidCompare(&Uuid, &Uuid3) == 0); 123 RTTEST_CHECK(hTest, memcmp(&Uuid3, &Uuid, sizeof(Uuid)) == 0); 107 124 108 125 /* 109 126 * checking the clock seq and time hi and version bits... 110 127 */ 128 RTTestSub(hTest, "Clock seq, time hi, version bits"); 111 129 RTUUID Uuid4Changes; 112 130 Uuid4Changes.au64[0] = 0; … … 167 185 Uuid4Fixed.au64[0] = ~Uuid4Changes.au64[0]; 168 186 Uuid4Fixed.au64[1] = ~Uuid4Changes.au64[1]; 169 RT Printf("tstUuid:fixed bits: %RTuuid (mask)\n", &Uuid4Fixed);170 RT Printf("tstUuid: raw: %.*Rhxs\n", sizeof(Uuid4Fixed), &Uuid4Fixed);187 RTTestPrintf(hTest, RTTESTLVL_INFO, "fixed bits: %RTuuid (mask)\n", &Uuid4Fixed); 188 RTTestPrintf(hTest, RTTESTLVL_INFO, "tstUuid: raw: %.*Rhxs\n", sizeof(Uuid4Fixed), &Uuid4Fixed); 171 189 172 190 Uuid4Prev.au64[0] &= Uuid4Fixed.au64[0]; 173 191 Uuid4Prev.au64[1] &= Uuid4Fixed.au64[1]; 174 RT Printf("tstUuid: fixed bits: %RTuuid (value)\n", &Uuid4Prev);175 RT Printf("tstUuid: raw: %.*Rhxs\n", sizeof(Uuid4Prev), &Uuid4Prev);192 RTTestPrintf(hTest, RTTESTLVL_INFO, "tstUuid: fixed bits: %RTuuid (value)\n", &Uuid4Prev); 193 RTTestPrintf(hTest, RTTESTLVL_INFO, "tstUuid: raw: %.*Rhxs\n", sizeof(Uuid4Prev), &Uuid4Prev); 176 194 177 195 /* 178 196 * Summary. 179 197 */ 180 if (!cErrors) 181 RTPrintf("tstUuid: SUCCESS {%s}\n", sz); 182 else 183 RTPrintf("tstUuid: FAILED - %d errors\n", cErrors); 184 return !!cErrors; 198 return RTTestSummaryAndDestroy(hTest); 185 199 } 186 200
Note:
See TracChangeset
for help on using the changeset viewer.