Changeset 80827 in vbox for trunk/src/VBox/Runtime/testcase
- Timestamp:
- Sep 16, 2019 2:04:02 PM (5 years ago)
- Location:
- trunk/src/VBox/Runtime/testcase
- Files:
-
- 1 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/testcase/Makefile.kmk
r80708 r80827 62 62 tstDir-3 \ 63 63 tstRTDvm \ 64 tst Env \64 tstRTEnv \ 65 65 tstRTErrUnique \ 66 66 tstFile \ … … 347 347 tstRTDvm_SOURCES = tstRTDvm.cpp 348 348 349 tst Env_TEMPLATE = VBOXR3TSTEXE350 tst Env_SOURCES = tstEnv.cpp349 tstRTEnv_TEMPLATE = VBOXR3TSTEXE 350 tstRTEnv_SOURCES = tstRTEnv.cpp 351 351 352 352 tstRTErrUnique_SOURCES = tstRTErrUnique.cpp -
trunk/src/VBox/Runtime/testcase/tstRTEnv.cpp
r80826 r80827 30 30 *********************************************************************************************************************************/ 31 31 #include <iprt/env.h> 32 #include <iprt/initterm.h>33 32 #include <iprt/err.h> 34 33 #include <iprt/string.h> 35 #include <iprt/ stream.h>34 #include <iprt/test.h> 36 35 37 36 38 37 int main() 39 38 { 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"); 48 50 49 51 /* … … 173 175 CHECK_STR(szBuf, "MyValue15"); 174 176 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 175 189 /* 176 190 * Put. 177 191 */ 192 RTTestSub(hTest, "RTEnvPutEx"); 178 193 CHECK_RC(RTEnvPutEx(Env, "IPRTMyNewVar28"), VINF_SUCCESS); 179 194 CHECK(!RTEnvExistEx(Env, "IPRTMyNewVar28")); … … 191 206 CHECK_STR(szBuf, "MyValue15"); 192 207 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 193 220 /* 194 221 * Dup. 195 222 */ 223 RTTestSub(hTest, "RTEnvDupEx"); 196 224 char *psz1; 197 225 CHECK(RTEnvDupEx(Env, "NonExistantVariable") == NULL); … … 215 243 * Another cloning. 216 244 */ 245 RTTestSub(hTest, "RTEnvClone"); 217 246 RTENV Env2; 218 247 CHECK_RC(RTEnvClone(&Env2, Env), VINF_SUCCESS); … … 222 251 * execve envp and we're done. 223 252 */ 253 RTTestSub(hTest, "RTEnvGetExecEnvP"); 224 254 const char * const *papsz = RTEnvGetExecEnvP(RTENV_DEFAULT); 225 255 CHECK(papsz != NULL); … … 237 267 * Summary 238 268 */ 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); 244 270 } 245 271
Note:
See TracChangeset
for help on using the changeset viewer.