Changeset 19925 in vbox
- Timestamp:
- May 22, 2009 11:15:42 PM (16 years ago)
- svn:sync-xref-src-repo-rev:
- 47627
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/testcase/tstPath.cpp
r19924 r19925 33 33 *******************************************************************************/ 34 34 #include <iprt/path.h> 35 36 #include <iprt/err.h> 37 #include <iprt/initterm.h> 38 #include <iprt/param.h> 35 39 #include <iprt/process.h> 36 #include <iprt/initterm.h>37 40 #include <iprt/stream.h> 38 41 #include <iprt/string.h> 39 #include <iprt/err.h> 40 #include <iprt/param.h> 41 42 43 #define CHECK_RC(method) \ 44 do { \ 45 rc = method; \ 46 if (RT_FAILURE(rc)) \ 47 { \ 48 cErrors++; \ 49 RTPrintf("\ntstPath: FAILED calling " #method " at line %d: rc=%Rrc\n", __LINE__, rc); \ 50 } \ 51 } while (0) 42 #include <iprt/test.h> 43 52 44 53 45 int main() 54 46 { 55 47 /* 56 * Init RT. 57 */ 58 int rc; 59 int cErrors = 0; 60 CHECK_RC(RTR3Init()); 48 * Init RT+Test. 49 */ 50 int rc = RTR3Init(); 61 51 if (RT_FAILURE(rc)) 62 52 return 1; 63 53 54 RTTEST hTest; 55 rc = RTTestCreate("tstPath", &hTest); 56 if (RT_FAILURE(rc)) 57 return 1; 58 RTTestBanner(hTest); 59 64 60 /* 65 61 * RTPathExecDir, RTPathUserHome and RTProcGetExecutableName. 66 62 */ 63 RTTestSub(hTest, "RTPathExecDir"); 67 64 char szPath[RTPATH_MAX]; 68 CHECK_RC(RTPathExecDir(szPath, sizeof(szPath)));65 RTTESTI_CHECK_RC(RTPathExecDir(szPath, sizeof(szPath)), VINF_SUCCESS); 69 66 if (RT_SUCCESS(rc)) 70 RTPrintf("ExecDir={%s}\n", szPath); 71 CHECK_RC(RTPathUserHome(szPath, sizeof(szPath))); 67 RTTestIPrintf(RTTESTLVL_INFO, "ExecDir={%s}\n", szPath); 68 69 RTTestSub(hTest, "RTProcGetExecutableName"); 70 if (RTProcGetExecutableName(szPath, sizeof(szPath)) == szPath) 71 RTTestIPrintf(RTTESTLVL_INFO, "ExecutableName={%s}\n", szPath); 72 else 73 RTTestIFailed("RTProcGetExecutableName -> NULL"); 74 75 RTTestSub(hTest, "RTPathUserHome"); 76 RTTESTI_CHECK_RC(RTPathUserHome(szPath, sizeof(szPath)), VINF_SUCCESS); 72 77 if (RT_SUCCESS(rc)) 73 RTPrintf("UserHome={%s}\n", szPath); 74 if (RTProcGetExecutableName(szPath, sizeof(szPath)) == szPath) 75 RTPrintf("ExecutableName={%s}\n", szPath); 76 else 77 { 78 RTPrintf("tstPath: FAILED - RTProcGetExecutableName\n"); 79 cErrors++; 80 } 81 78 RTTestIPrintf(RTTESTLVL_INFO, "UserHome={%s}\n", szPath); 82 79 83 80 /* 84 81 * RTPathAbsEx 85 82 */ 86 RT Printf("tstPath: TESTING RTPathAbsEx()\n");83 RTTestSub(hTest, "RTPathAbsEx"); 87 84 static const struct 88 85 { … … 153 150 if (rc != s_aRTPathAbsExTests[i].rc) 154 151 { 155 RTPrintf("tstPath: RTPathAbsEx unexpected result code!\n" 156 " input base: '%s'\n" 157 " input path: '%s'\n" 158 " output: '%s'\n" 159 " rc: %Rrc\n" 160 " expected rc: %Rrc\n", 161 s_aRTPathAbsExTests[i].pcszInputBase, 162 s_aRTPathAbsExTests[i].pcszInputPath, 163 szPath, rc, 164 s_aRTPathAbsExTests[i].rc); 165 cErrors++; 152 RTTestIFailed("unexpected result code!\n" 153 " input base: '%s'\n" 154 " input path: '%s'\n" 155 " output: '%s'\n" 156 " rc: %Rrc\n" 157 " expected rc: %Rrc", 158 s_aRTPathAbsExTests[i].pcszInputBase, 159 s_aRTPathAbsExTests[i].pcszInputPath, 160 szPath, rc, 161 s_aRTPathAbsExTests[i].rc); 166 162 continue; 167 163 } … … 173 169 if (s_aRTPathAbsExTests[i].pcszOutput[0] == '%') 174 170 { 175 rc = RTPathGetCurrent(szTmp, sizeof(szTmp));171 RTTESTI_CHECK_RC(rc = RTPathGetCurrent(szTmp, sizeof(szTmp)), VINF_SUCCESS); 176 172 if (RT_FAILURE(rc)) 177 {178 RTPrintf("tstPath: RTPathGetCurrent failed with rc=%Rrc!\n", rc);179 cErrors++;180 173 break; 181 }182 174 183 175 pszExpected = szTmp; … … 205 197 if (strcmp(szPath, pszExpected)) 206 198 { 207 RTPrintf("tstPath: RTPathAbsEx failed!\n" 208 " input base: '%s'\n" 209 " input path: '%s'\n" 210 " output: '%s'\n" 211 " expected: '%s'\n", 212 s_aRTPathAbsExTests[i].pcszInputBase, 213 s_aRTPathAbsExTests[i].pcszInputPath, 214 szPath, 215 s_aRTPathAbsExTests[i].pcszOutput); 216 cErrors++; 199 RTTestIFailed("Unexpected result\n" 200 " input base: '%s'\n" 201 " input path: '%s'\n" 202 " output: '%s'\n" 203 " expected: '%s'", 204 s_aRTPathAbsExTests[i].pcszInputBase, 205 s_aRTPathAbsExTests[i].pcszInputPath, 206 szPath, 207 s_aRTPathAbsExTests[i].pcszOutput); 217 208 } 218 209 } … … 222 213 * RTPathStripFilename 223 214 */ 224 RT Printf("tstPath: RTPathStripFilename...\n");215 RTTestSub(hTest, "RTPathStripFilename"); 225 216 static const char *s_apszStripFilenameTests[] = 226 217 { … … 246 237 if (strcmp(szPath, pszExpect)) 247 238 { 248 RTPrintf("tstPath: RTPathStripFilename failed!\n" 249 " input: '%s'\n" 250 " output: '%s'\n" 251 "expected: '%s'\n", 252 pszInput, szPath, pszExpect); 253 cErrors++; 239 RTTestIFailed("Unexpected result\n" 240 " input: '%s'\n" 241 " output: '%s'\n" 242 "expected: '%s'", 243 pszInput, szPath, pszExpect); 254 244 } 255 245 } 256 246 257 247 /* 248 * RTPathAppend. 249 */ 250 251 252 253 /* 258 254 * Summary. 259 255 */ 260 if (!cErrors) 261 RTPrintf("tstPath: SUCCESS\n"); 262 else 263 RTPrintf("tstPath: FAILURE %d errors\n", cErrors); 264 return !!cErrors; 256 return RTTestSummaryAndDestroy(hTest); 265 257 } 266 258
Note:
See TracChangeset
for help on using the changeset viewer.