~ubuntu-branches/ubuntu/raring/virtualbox-ose/raring

« back to all changes in this revision

Viewing changes to src/VBox/Runtime/testcase/tstRTUuid.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Felix Geyer
  • Date: 2011-01-30 23:27:25 UTC
  • mfrom: (0.3.12 upstream)
  • Revision ID: james.westby@ubuntu.com-20110130232725-2ouajjd2ggdet0zd
Tags: 4.0.2-dfsg-1ubuntu1
* Merge from Debian unstable, remaining changes:
  - Add Apport hook.
    - debian/virtualbox-ose.files/source_virtualbox-ose.py
    - debian/virtualbox-ose.install
  - Drop *-source packages.
* Drop ubuntu-01-fix-build-gcc45.patch, fixed upstream.
* Drop ubuntu-02-as-needed.patch, added to the Debian package.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $Id: tstRTUuid.cpp $ */
 
1
/* $Id: tstRTUuid.cpp 32996 2010-10-08 08:12:41Z vboxsync $ */
2
2
/** @file
3
3
 * IPRT Testcase - UUID.
4
4
 */
74
74
    rc = RTUuidFromStr(&Uuid2, sz); CHECK_RC();
75
75
    RTTEST_CHECK(hTest, RTUuidCompare(&Uuid, &Uuid2) == 0);
76
76
 
 
77
    char *psz = (char *)RTTestGuardedAllocTail(hTest, RTUUID_STR_LENGTH);
 
78
    if (psz)
 
79
    {
 
80
        RTStrPrintf(psz, RTUUID_STR_LENGTH, "%s", sz);
 
81
        RTTESTI_CHECK_RC(RTUuidFromStr(&Uuid2, psz), VINF_SUCCESS);
 
82
        RTTEST_CHECK(hTest, RTUuidCompare(&Uuid, &Uuid2) == 0);
 
83
        for (unsigned off = 1; off < RTUUID_STR_LENGTH; off++)
 
84
        {
 
85
            char *psz2 = psz + off;
 
86
            RTStrPrintf(psz2, RTUUID_STR_LENGTH - off, "%s", sz);
 
87
            RTTESTI_CHECK_RC(RTUuidFromStr(&Uuid2, psz2), VERR_INVALID_UUID_FORMAT);
 
88
        }
 
89
        RTTestGuardedFree(hTest, psz);
 
90
    }
 
91
 
 
92
    RTUuidClear(&Uuid2);
 
93
    char sz2[RTUUID_STR_LENGTH + 2];
 
94
    RTStrPrintf(sz2, sizeof(sz2), "{%s}", sz);
 
95
    rc = RTUuidFromStr(&Uuid2, sz2); CHECK_RC();
 
96
    RTTEST_CHECK(hTest, RTUuidCompare(&Uuid, &Uuid2) == 0);
 
97
 
 
98
    psz = (char *)RTTestGuardedAllocTail(hTest, RTUUID_STR_LENGTH + 2);
 
99
    if (psz)
 
100
    {
 
101
        RTStrPrintf(psz, RTUUID_STR_LENGTH + 2, "{%s}", sz);
 
102
        RTTESTI_CHECK_RC(RTUuidFromStr(&Uuid2, psz), VINF_SUCCESS);
 
103
        RTTEST_CHECK(hTest, RTUuidCompare(&Uuid, &Uuid2) == 0);
 
104
        for (unsigned off = 1; off < RTUUID_STR_LENGTH + 2; off++)
 
105
        {
 
106
            char *psz2 = psz + off;
 
107
            RTStrPrintf(psz2, RTUUID_STR_LENGTH + 2 - off, "{%s}", sz);
 
108
            RTTESTI_CHECK_RC(RTUuidFromStr(&Uuid2, psz2), VERR_INVALID_UUID_FORMAT);
 
109
        }
 
110
        RTTestGuardedFree(hTest, psz);
 
111
    }
 
112
 
77
113
    RTTestSub(hTest, "RTUuidToUtf16");
78
114
    RTUTF16 wsz[RTUUID_STR_LENGTH];
79
115
    rc = RTUuidToUtf16(&Uuid, wsz, sizeof(wsz)); CHECK_RC();
83
119
    rc = RTUuidFromUtf16(&Uuid2, wsz); CHECK_RC();
84
120
    RTTEST_CHECK(hTest, RTUuidCompare(&Uuid, &Uuid2) == 0);
85
121
 
 
122
    RTUTF16 *pwsz;
 
123
    rc = RTStrToUtf16(sz2, &pwsz);
 
124
    RTTEST_CHECK(hTest, rc == VINF_SUCCESS);
 
125
    if (RT_SUCCESS(rc))
 
126
    {
 
127
        RTTESTI_CHECK_RC(RTUuidFromUtf16(&Uuid2, pwsz), VINF_SUCCESS);
 
128
        RTTEST_CHECK(hTest, RTUuidCompare(&Uuid, &Uuid2) == 0);
 
129
        RTUTF16 *pwsz2 = (RTUTF16*)RTTestGuardedAllocTail(hTest, 2 * (RTUUID_STR_LENGTH + 2));
 
130
        if (pwsz2)
 
131
        {
 
132
            memcpy(pwsz2, pwsz, 2 * (RTUUID_STR_LENGTH + 2));
 
133
            RTTESTI_CHECK_RC(RTUuidFromUtf16(&Uuid2, pwsz2), VINF_SUCCESS);
 
134
            RTTEST_CHECK(hTest, RTUuidCompare(&Uuid, &Uuid2) == 0);
 
135
            for (unsigned off = 1; off < RTUUID_STR_LENGTH + 2; off++)
 
136
            {
 
137
                RTUTF16 *pwsz3 = pwsz2 + off;
 
138
                memcpy(pwsz3, pwsz, 2 * (RTUUID_STR_LENGTH + 1 - off));
 
139
                pwsz3[RTUUID_STR_LENGTH + 1 - off] = 0;
 
140
                RTTESTI_CHECK_RC(RTUuidFromUtf16(&Uuid2, pwsz3), VERR_INVALID_UUID_FORMAT);
 
141
            }
 
142
            RTTestGuardedFree(hTest, pwsz2);
 
143
        }
 
144
        RTUtf16Free(pwsz);
 
145
    }
 
146
 
86
147
    RTTestSub(hTest, "RTUuidCompareStr");
87
148
    RTTEST_CHECK(hTest, RTUuidCompareStr(&Uuid, sz) == 0);
88
149
    RTTEST_CHECK(hTest, RTUuidCompareStr(&Uuid, "00000000-0000-0000-0000-000000000000") > 0);