VirtualBox

Changeset 19205 in vbox


Ignore:
Timestamp:
Apr 27, 2009 10:03:40 AM (16 years ago)
Author:
vboxsync
Message:

tstUuid: Updated to RTTest and added tests for the new Utf16 functions.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/testcase/tstUuid.cpp

    r13837 r19205  
    3434*******************************************************************************/
    3535#include <iprt/uuid.h>
     36#include <iprt/test.h>
    3637#include <iprt/stream.h>
    3738#include <iprt/err.h>
     
    4344{
    4445    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)))
    4949    {
    50         RTPrintf("RTR3Init failed: %Rrc\n", rc);
     50        RTPrintf("tstUuid: RTR3Init or RTTestCreate failed: %Rrc\n", rc);
    5151        return 1;
    5252    }
    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");
    5960    RTUUID UuidNull;
    6061    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");
    6467    RTUUID Uuid;
    6568    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");
    7175    char sz[RTUUID_STR_LENGTH];
    7276    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");
    7381    RTUUID Uuid2;
    7482    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
    7894
    7995    /*
    8096     * Check the binary representation.
    8197     */
     98    RTTestSub(hTest, "Binary representation");
    8299    RTUUID Uuid3;
    83100    Uuid3.au8[0]  = 0x01;
     
    101118    const char *pszUuid3 = "67452301-ab89-4fcd-90b2-547698badcfe";
    102119    rc = RTUuidToStr(&Uuid3, sz, sizeof(sz)); CHECK_RC();
    103     CHECK_EXPR(strcmp(sz, pszUuid3) == 0);
     120    RTTEST_CHECK(hTest, strcmp(sz, pszUuid3) == 0);
    104121    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);
    107124
    108125    /*
    109126     * checking the clock seq and time hi and version bits...
    110127     */
     128    RTTestSub(hTest, "Clock seq, time hi, version bits");
    111129    RTUUID Uuid4Changes;
    112130    Uuid4Changes.au64[0] = 0;
     
    167185    Uuid4Fixed.au64[0] = ~Uuid4Changes.au64[0];
    168186    Uuid4Fixed.au64[1] = ~Uuid4Changes.au64[1];
    169     RTPrintf("tstUuid: fixed bits: %RTuuid (mask)\n", &Uuid4Fixed);
    170     RTPrintf("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);
    171189
    172190    Uuid4Prev.au64[0] &= Uuid4Fixed.au64[0];
    173191    Uuid4Prev.au64[1] &= Uuid4Fixed.au64[1];
    174     RTPrintf("tstUuid: fixed bits: %RTuuid (value)\n", &Uuid4Prev);
    175     RTPrintf("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);
    176194
    177195    /*
    178196     * Summary.
    179197     */
    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);
    185199}
    186200
Note: See TracChangeset for help on using the changeset viewer.

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