VirtualBox

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


Ignore:
Timestamp:
Sep 16, 2019 2:04:02 PM (5 years ago)
Author:
vboxsync
Message:

IPRT: Added RTEnvCreateEx and RTEnvCreateChangeRecordEx so flags can be specified when creating custom environments. Defined one flag RTENV_CREATE_F_ALLOW_EQUAL_FIRST_IN_VAR for accomodating windows style environment variables (used for CWD by driver letter). The flag is set by default on windows hosts, however it does not work for the default environment due to CRT limitations.

Location:
trunk/src/VBox/Runtime/testcase
Files:
1 edited
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/testcase/Makefile.kmk

    r80708 r80827  
    6262        tstDir-3 \
    6363        tstRTDvm \
    64         tstEnv \
     64        tstRTEnv \
    6565        tstRTErrUnique \
    6666        tstFile \
     
    347347tstRTDvm_SOURCES = tstRTDvm.cpp
    348348
    349 tstEnv_TEMPLATE = VBOXR3TSTEXE
    350 tstEnv_SOURCES = tstEnv.cpp
     349tstRTEnv_TEMPLATE = VBOXR3TSTEXE
     350tstRTEnv_SOURCES = tstRTEnv.cpp
    351351
    352352tstRTErrUnique_SOURCES = tstRTErrUnique.cpp
  • trunk/src/VBox/Runtime/testcase/tstRTEnv.cpp

    r80826 r80827  
    3030*********************************************************************************************************************************/
    3131#include <iprt/env.h>
    32 #include <iprt/initterm.h>
    3332#include <iprt/err.h>
    3433#include <iprt/string.h>
    35 #include <iprt/stream.h>
     34#include <iprt/test.h>
    3635
    3736
    3837int main()
    3938{
    40     RTR3InitExeNoArguments(0);
    41     RTPrintf("tstEnv: TESTING...\n");
    42 
    43     int cErrors = 0;
    44 
    45 #define CHECK(expr)  do { if (!(expr)) { RTPrintf("tstEnv: error line %d: %s\n", __LINE__, #expr); cErrors++; } } while (0)
    46 #define CHECK_RC(expr, rc)  do { int rc2 = expr; if (rc2 != (rc)) { RTPrintf("tstEnv: error line %d: %s -> %Rrc expected %Rrc\n", __LINE__, #expr, rc2, rc); cErrors++; } } while (0)
    47 #define CHECK_STR(str1, str2)  do { if (strcmp(str1, str2)) { RTPrintf("tstEnv: error line %d: '%s' != '%s' (*)\n", __LINE__, str1, str2); cErrors++; } } while (0)
     39    RTTEST hTest;
     40    RTEXITCODE rcExit = RTTestInitAndCreate("tstRTEnv", &hTest);
     41    if (rcExit != RTEXITCODE_SUCCESS)
     42        return rcExit;
     43    RTTestBanner(hTest);
     44
     45#define CHECK(expr)             RTTEST_CHECK(hTest, expr)
     46#define CHECK_RC(expr, rc)      RTTEST_CHECK_RC(hTest, expr, rc)
     47#define CHECK_STR(str1, str2)  do { if (strcmp(str1, str2)) { RTTestFailed(hTest, "line %u: '%s' != '%s' (*)", __LINE__, str1, str2); } } while (0)
     48
     49    RTTestSub(hTest, "Basics");
    4850
    4951    /*
     
    173175    CHECK_STR(szBuf, "MyValue15");
    174176
     177    RTTestDisableAssertions(hTest);
     178#ifdef RT_OS_WINDOWS
     179    CHECK_RC(RTEnvSetEx(Env, "=C:", "C:\\Temp"), VINF_SUCCESS);
     180    CHECK_RC(RTEnvGetEx(Env, "=C:", szBuf, sizeof(szBuf), &cch), VINF_SUCCESS);
     181    CHECK_STR(szBuf, "C:\\Temp");
     182#else
     183    CHECK_RC(RTEnvSetEx(Env, "=C:", "C:\\Temp"), VERR_ENV_INVALID_VAR_NAME);
     184    CHECK_RC(RTEnvSetEx(Env, "=", ""), VERR_ENV_INVALID_VAR_NAME);
     185#endif
     186    CHECK_RC(RTEnvSetEx(Env, "", ""), VERR_ENV_INVALID_VAR_NAME);
     187    RTTestRestoreAssertions(hTest);
     188
    175189    /*
    176190     * Put.
    177191     */
     192    RTTestSub(hTest, "RTEnvPutEx");
    178193    CHECK_RC(RTEnvPutEx(Env, "IPRTMyNewVar28"), VINF_SUCCESS);
    179194    CHECK(!RTEnvExistEx(Env, "IPRTMyNewVar28"));
     
    191206    CHECK_STR(szBuf, "MyValue15");
    192207
     208    RTTestDisableAssertions(hTest);
     209#ifdef RT_OS_WINDOWS
     210    CHECK_RC(RTEnvPutEx(Env, "=D:=D:\\Temp"), VINF_SUCCESS);
     211    CHECK_RC(RTEnvGetEx(Env, "=D:", szBuf, sizeof(szBuf), &cch), VINF_SUCCESS);
     212    CHECK_STR(szBuf, "D:\\Temp");
     213#else
     214    CHECK_RC(RTEnvPutEx(Env, "=D:=D:\\Temp"), VERR_ENV_INVALID_VAR_NAME);
     215    CHECK_RC(RTEnvPutEx(Env, "="), VERR_ENV_INVALID_VAR_NAME);
     216#endif
     217    CHECK_RC(RTEnvPutEx(Env, ""), VERR_ENV_INVALID_VAR_NAME);
     218    RTTestRestoreAssertions(hTest);
     219
    193220    /*
    194221     * Dup.
    195222     */
     223    RTTestSub(hTest, "RTEnvDupEx");
    196224    char *psz1;
    197225    CHECK(RTEnvDupEx(Env, "NonExistantVariable") == NULL);
     
    215243     * Another cloning.
    216244     */
     245    RTTestSub(hTest, "RTEnvClone");
    217246    RTENV Env2;
    218247    CHECK_RC(RTEnvClone(&Env2, Env), VINF_SUCCESS);
     
    222251     * execve envp and we're done.
    223252     */
     253    RTTestSub(hTest, "RTEnvGetExecEnvP");
    224254    const char * const *papsz = RTEnvGetExecEnvP(RTENV_DEFAULT);
    225255    CHECK(papsz != NULL);
     
    237267     * Summary
    238268     */
    239     if (!cErrors)
    240         RTPrintf("tstEnv: SUCCESS\n");
    241     else
    242         RTPrintf("tstEnv: FAILURE - %d errors\n", cErrors);
    243     return !!cErrors;
     269    return RTTestSummaryAndDestroy(hTest);
    244270}
    245271
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