VirtualBox

Ignore:
Timestamp:
Sep 18, 2019 10:32:20 AM (5 years ago)
Author:
vboxsync
Message:

IPRT/env-generic.cpp: RTENV_ALLOW_EQUAL_FIRST_IN_VAR should only be used for defaults, not for the set, unset and put APIs. Some other fixes in the same area. Added some more tests to tstRTEnv.

File:
1 edited

Legend:

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

    r80827 r80878  
    6666    CHECK(RTEnvGet(k_pszPathVar) != NULL);
    6767    char szBuf[8192];
     68    char szBuf2[1024];
    6869    size_t cch;
    6970    CHECK_RC(RTEnvGetEx(RTENV_DEFAULT, k_pszPathVar, NULL, 0, &cch), VINF_SUCCESS);
     
    7778    RTENV Env;
    7879    CHECK_RC(RTEnvClone(&Env, RTENV_DEFAULT), VINF_SUCCESS);
     80    RTENV hEnvEq;
     81    CHECK_RC(RTEnvCreateEx(&hEnvEq, RTENV_CREATE_F_ALLOW_EQUAL_FIRST_IN_VAR), VINF_SUCCESS);
     82    RTENV hEnvNoEq;
     83    CHECK_RC(RTEnvCreateEx(&hEnvNoEq, 0), VINF_SUCCESS);
    7984
    8085    CHECK(RTEnvExistEx(Env, k_pszPathVar));
     
    8792    CHECK_RC(RTEnvGetEx(Env, k_pszPathVar, szBuf, 1, &cch), VERR_BUFFER_OVERFLOW);
    8893    CHECK_RC(RTEnvGetEx(Env, k_pszPathVar, szBuf, 1, NULL), VERR_BUFFER_OVERFLOW);
     94
     95    CHECK_RC(RTEnvGetEx(hEnvEq, k_pszPathVar, szBuf, sizeof(szBuf), NULL), VERR_ENV_VAR_NOT_FOUND);
     96    CHECK_RC(RTEnvGetEx(hEnvEq, k_pszPathVar, szBuf, 0, &cch), VERR_ENV_VAR_NOT_FOUND);
     97    CHECK_RC(RTEnvGetEx(hEnvEq, "=D:", szBuf, 1, NULL), VERR_ENV_VAR_NOT_FOUND);
     98    CHECK_RC(RTEnvGetEx(hEnvNoEq, k_pszPathVar, szBuf, sizeof(szBuf), &cch), VERR_ENV_VAR_NOT_FOUND);
     99    CHECK_RC(RTEnvGetEx(hEnvNoEq, k_pszPathVar, szBuf, 1, NULL), VERR_ENV_VAR_NOT_FOUND);
     100    RTTestDisableAssertions(hTest);
     101    CHECK_RC(RTEnvGetEx(hEnvNoEq, "=D:", szBuf, 1, NULL), VERR_ENV_INVALID_VAR_NAME);
     102    RTTestRestoreAssertions(hTest);
    89103
    90104    /*
     
    187201    RTTestRestoreAssertions(hTest);
    188202
     203    CHECK_RC(RTEnvSetEx(hEnvEq, "=D:", "D:\\TMP"), VINF_SUCCESS);
     204    CHECK_RC(RTEnvGetEx(hEnvEq, "=D:", szBuf, sizeof(szBuf), &cch), VINF_SUCCESS);
     205    CHECK_STR(szBuf, "D:\\TMP");
     206    RTTESTI_CHECK(RTEnvExistEx(hEnvEq, "=D:") == true);
     207    CHECK_RC(RTEnvUnsetEx(hEnvEq, "=D:"), VINF_SUCCESS);
     208    CHECK_RC(RTEnvUnsetEx(hEnvEq, "=D:"), VINF_ENV_VAR_NOT_FOUND);
     209    RTTESTI_CHECK(RTEnvExistEx(hEnvEq, "=D:") == false);
     210
     211    RTTestDisableAssertions(hTest);
     212    CHECK_RC(RTEnvSetEx(hEnvNoEq, "=D:", "D:\\TMP"), VERR_ENV_INVALID_VAR_NAME);
     213    CHECK_RC(RTEnvGetEx(hEnvNoEq, "=D:", szBuf, sizeof(szBuf), &cch), VERR_ENV_INVALID_VAR_NAME);
     214    CHECK_RC(RTEnvUnsetEx(hEnvNoEq, "=D:"), VERR_ENV_INVALID_VAR_NAME);
     215    RTTESTI_CHECK(RTEnvExistEx(hEnvNoEq, "=D:") == false);
     216    RTTestRestoreAssertions(hTest);
     217
    189218    /*
    190219     * Put.
     
    218247    RTTestRestoreAssertions(hTest);
    219248
     249    CHECK_RC(RTEnvPutEx(hEnvEq, "=C:=C:\\"), VINF_SUCCESS);
     250    CHECK_RC(RTEnvPutEx(hEnvEq, "=E:=E:\\TEMP"), VINF_SUCCESS);
     251    CHECK_RC(RTEnvGetEx(hEnvEq, "=E:", szBuf, sizeof(szBuf), &cch), VINF_SUCCESS);
     252    CHECK_STR(szBuf, "E:\\TEMP");
     253    RTTESTI_CHECK(RTEnvExistEx(hEnvEq, "=E:") == true);
     254    CHECK_RC(RTEnvPutEx(hEnvEq, "=E:"), VINF_SUCCESS);
     255    CHECK_RC(RTEnvPutEx(hEnvEq, "=E:"), VINF_ENV_VAR_NOT_FOUND);
     256    CHECK_RC(RTEnvGetEx(hEnvEq, "=E:", szBuf, sizeof(szBuf), &cch), VERR_ENV_VAR_NOT_FOUND);
     257    CHECK_RC(RTEnvGetEx(hEnvEq, "=C:", szBuf, sizeof(szBuf), &cch), VINF_SUCCESS);
     258    CHECK_STR(szBuf, "C:\\");
     259    CHECK_RC(RTEnvGetByIndexEx(hEnvEq, 0, szBuf2, sizeof(szBuf2), szBuf, sizeof(szBuf)), VINF_SUCCESS);
     260    CHECK_STR(szBuf2, "=C:");
     261    CHECK_STR(szBuf, "C:\\");
     262    CHECK_RC(RTEnvGetByIndexEx(hEnvEq, 1, szBuf2, sizeof(szBuf2), szBuf, sizeof(szBuf)), VERR_ENV_VAR_NOT_FOUND);
     263    RTTESTI_CHECK(RTEnvExistEx(hEnvEq, "=C:") == true);
     264
     265    RTTestDisableAssertions(hTest);
     266    CHECK_RC(RTEnvPutEx(hEnvNoEq, "=C:=C:\\"), VERR_ENV_INVALID_VAR_NAME);
     267    CHECK_RC(RTEnvPutEx(hEnvNoEq, "=E:=E:\\TEMP"), VERR_ENV_INVALID_VAR_NAME);
     268    CHECK_RC(RTEnvPutEx(hEnvNoEq, "=E:"), VERR_ENV_INVALID_VAR_NAME);
     269    RTTESTI_CHECK(RTEnvExistEx(hEnvNoEq, "=C:") == false);
     270    RTTestRestoreAssertions(hTest);
     271
    220272    /*
    221273     * Dup.
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