VirtualBox

Changeset 57916 in vbox for trunk/src/VBox/Runtime/testcase


Ignore:
Timestamp:
Sep 27, 2015 8:36:38 PM (9 years ago)
Author:
vboxsync
Message:

IPRT: More windows process creation hacking and cleaning up. Cleaned up RTProcQueryUsername and RTProcQueryUsernameA too (all platforms).

File:
1 edited

Legend:

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

    r57358 r57916  
    3535#include <iprt/test.h>
    3636
     37
    3738static void tstRTProcQueryUsername(void)
    3839{
    39     char abUser[1024];
    40     size_t cbUser;
    41     char *pszUser = NULL;
    42 
    4340    RTTestISub("Basics");
    4441
    45     memset(abUser, 0, sizeof(abUser));
     42    size_t  cbUser;
     43    char    szUser[1024];
     44    memset(szUser, '-', sizeof(szUser));
     45
     46    /* negative stuff that may assert: */
     47    bool fMayPanic = RTAssertSetMayPanic(false);
     48    bool fQuiet    = RTAssertSetQuiet(true);
     49
    4650    RTTESTI_CHECK_RC(RTProcQueryUsername(RTProcSelf(), NULL, 8, &cbUser), VERR_INVALID_PARAMETER);
    47     RTTESTI_CHECK_RC(RTProcQueryUsername(RTProcSelf(), abUser, 0, &cbUser), VERR_INVALID_PARAMETER);
    48     RTTESTI_CHECK_RC(RTProcQueryUsername(RTProcSelf(), NULL, 0, NULL), VERR_BUFFER_OVERFLOW);
     51    RTTESTI_CHECK_RC(RTProcQueryUsername(RTProcSelf(), szUser, 0, &cbUser), VERR_INVALID_PARAMETER);
     52    RTTESTI_CHECK_RC(RTProcQueryUsername(RTProcSelf(), NULL, 0, NULL), VERR_INVALID_PARAMETER);
     53    RTTESTI_CHECK_RC(RTProcQueryUsernameA(RTProcSelf(), NULL), VERR_INVALID_POINTER);
     54
     55    RTAssertSetMayPanic(fMayPanic);
     56    RTAssertSetQuiet(fQuiet);
     57
    4958    RTTESTI_CHECK_RC(RTProcQueryUsername(RTProcSelf(), NULL, 0, &cbUser), VERR_BUFFER_OVERFLOW);
     59    memset(szUser, '-', sizeof(szUser));
     60    RTTESTI_CHECK_RC(RTProcQueryUsername(RTProcSelf(), szUser, cbUser - 1, &cbUser), VERR_BUFFER_OVERFLOW);
     61    memset(szUser, '-', sizeof(szUser));
     62    RTTESTI_CHECK_RC(RTProcQueryUsername(RTProcSelf(), szUser, sizeof(szUser), &cbUser), VINF_SUCCESS);
     63    RTTestPrintf(NULL, RTTESTLVL_ALWAYS, "Username: %s\n", szUser); /* */
    5064
    51     RTTESTI_CHECK_RC(RTProcQueryUsername(RTProcSelf(), abUser, sizeof(abUser), &cbUser), VINF_SUCCESS);
    52     RTTestPrintf(NULL, RTTESTLVL_ALWAYS, "Username: %s\n", abUser);
    53     RTTESTI_CHECK_RC(RTProcQueryUsername(RTProcSelf(), abUser, cbUser - 1, &cbUser), VERR_BUFFER_OVERFLOW);
    54 
    55     RTTESTI_CHECK_RC(RTProcQueryUsernameA(RTProcSelf(), NULL), VERR_INVALID_POINTER);
     65    char *pszUser = NULL;
    5666    RTTESTI_CHECK_RC(RTProcQueryUsernameA(RTProcSelf(), &pszUser), VINF_SUCCESS);
    5767    RTTestPrintf(NULL, RTTESTLVL_ALWAYS, "Username: %s\n", pszUser);
     68    RTTESTI_CHECK(strcmp(pszUser, szUser) == 0);
    5869    RTStrFree(pszUser);
    5970}
     71
    6072
    6173int main(int argc, char **argv)
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