Changeset 14369 in vbox for trunk/src/VBox
- Timestamp:
- Nov 19, 2008 6:19:32 PM (16 years ago)
- Location:
- trunk/src/VBox/Runtime/testcase
- Files:
-
- 1 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/testcase/Makefile.kmk
r14025 r14369 56 56 tstDir \ 57 57 tstDir-2 \ 58 tstDir-3 \ 58 59 tstEnv \ 59 60 tstErrUnique \ … … 145 146 tstDir-2_SOURCES = tstDir-2.cpp 146 147 148 tstDir-3_SOURCES = tstDir-3.cpp 149 147 150 tstEnv_SOURCES = tstEnv.cpp 148 151 -
trunk/src/VBox/Runtime/testcase/tstDir-3.cpp
r14339 r14369 1 1 /* $Id$ */ 2 2 /** @file 3 * IPRT Testcase - Directory listing & filtering .3 * IPRT Testcase - Directory listing & filtering (no parameters needed). 4 4 */ 5 5 6 6 /* 7 * Copyright (C) 2006-200 7Sun Microsystems, Inc.7 * Copyright (C) 2006-2008 Sun Microsystems, Inc. 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 29 29 */ 30 30 31 #include <iprt/path.h> 31 32 #include <iprt/dir.h> 32 33 #include <iprt/stream.h> … … 34 35 #include <iprt/runtime.h> 35 36 37 static int tstDirOpenFiltered(const char *pszFilter, unsigned *pcFilesMatch, int *pRc) 38 { 39 int rcRet = 0; 40 unsigned cFilesMatch = 0; 41 PRTDIR pDir; 42 int rc = RTDirOpenFiltered(&pDir, pszFilter, RTDIRFILTER_WINNT); 43 if (RT_SUCCESS(rc)) 44 { 45 for (;;) 46 { 47 RTDIRENTRY DirEntry; 48 rc = RTDirRead(pDir, &DirEntry, NULL); 49 if (RT_FAILURE(rc)) 50 break; 51 cFilesMatch++; 52 } 53 54 if (rc != VERR_NO_MORE_FILES) 55 { 56 RTPrintf("tstDir-3: Enumeration '%s' failed! rc=%Rrc\n", pszFilter, rc); 57 rcRet = 1; 58 } 59 60 /* close up */ 61 rc = RTDirClose(pDir); 62 if (RT_FAILURE(rc)) 63 { 64 RTPrintf("tstDir-3: Failed to close dir '%s'! rc=%Rrc\n", pszFilter, rc); 65 rcRet = 1; 66 } 67 } 68 else 69 { 70 RTPrintf("tstDir-3: Failed to open '%s', rc=%Rrc\n", pszFilter, rc); 71 rcRet = 1; 72 } 73 74 *pcFilesMatch = cFilesMatch; 75 *pRc = rc; 76 return rcRet; 77 } 78 36 79 int main(int argc, char **argv) 37 80 { 38 81 int rcRet = 0; 82 int rcRet2; 83 int rc; 84 unsigned cMatch; 39 85 RTR3Init(); 40 86 41 /* 42 * Iterate arguments. 43 */ 44 for (int i = 1; i < argc; i++) 87 const char *pszTestDir = "."; 88 89 char *pszFilter1 = NULL; 90 rc = RTStrAPrintf(&pszFilter1, "%s%c%s", pszTestDir, RTPATH_SLASH, "xyxzxq*"); 91 if (RT_FAILURE(rc)) 45 92 { 46 /* open */ 47 PRTDIR pDir; 48 int rc = RTDirOpenFiltered(&pDir, argv[i], RTDIRFILTER_WINNT); 49 if (RT_SUCCESS(rc)) 50 { 51 for (;;) 52 { 53 RTDIRENTRY DirEntry; 54 rc = RTDirRead(pDir, &DirEntry, NULL); 55 if (RT_FAILURE(rc)) 56 break; 57 switch (DirEntry.enmType) 58 { 59 case RTDIRENTRYTYPE_UNKNOWN: RTPrintf("u"); break; 60 case RTDIRENTRYTYPE_FIFO: RTPrintf("f"); break; 61 case RTDIRENTRYTYPE_DEV_CHAR: RTPrintf("c"); break; 62 case RTDIRENTRYTYPE_DIRECTORY: RTPrintf("d"); break; 63 case RTDIRENTRYTYPE_DEV_BLOCK: RTPrintf("b"); break; 64 case RTDIRENTRYTYPE_FILE: RTPrintf("-"); break; 65 case RTDIRENTRYTYPE_SYMLINK: RTPrintf("l"); break; 66 case RTDIRENTRYTYPE_SOCKET: RTPrintf("s"); break; 67 case RTDIRENTRYTYPE_WHITEOUT: RTPrintf("w"); break; 68 default: 69 rcRet = 1; 70 RTPrintf("?"); 71 break; 72 } 73 RTPrintf(" %#18llx %3d %s\n", (uint64_t)DirEntry.INodeId, 74 DirEntry.cbName, DirEntry.szName); 75 } 76 77 if (rc != VERR_NO_MORE_FILES) 78 { 79 RTPrintf("tstDir: Enumeration failed! rc=%Rrc\n", rc); 80 rcRet = 1; 81 } 82 83 /* close up */ 84 rc = RTDirClose(pDir); 85 if (RT_FAILURE(rc)) 86 { 87 RTPrintf("tstDir: Failed to close dir! rc=%Rrc\n", rc); 88 rcRet = 1; 89 } 90 } 91 else 92 { 93 RTPrintf("tstDir: Failed to open '%s', rc=%Rrc\n", argv[i], rc); 94 rcRet = 1; 95 } 93 RTPrintf("tstDir-3: cannot create non-match filter! rc=%Rrc\n", rc); 94 return 1; 96 95 } 97 96 97 char *pszFilter2 = NULL; 98 rc = RTStrAPrintf(&pszFilter2, "%s%c%s", pszTestDir, RTPATH_SLASH, "*"); 99 if (RT_FAILURE(rc)) 100 { 101 RTPrintf("tstDir-3: cannot create match filter! rc=%Rrc\n", rc); 102 return 1; 103 } 104 105 rcRet2 = tstDirOpenFiltered(pszFilter1, &cMatch, &rc); 106 if (rcRet2) 107 rcRet = rcRet2; 108 if (RT_FAILURE(rc)) 109 RTPrintf("tstDir-3: filter '%s' failed! rc=%Rrc\n", pszFilter1, rc); 110 if (cMatch) 111 RTPrintf("tstDir-3: filter '%s' gave wrong result count! cMatch=%u\n", pszFilter1, cMatch); 112 113 rcRet2 = tstDirOpenFiltered(pszFilter2, &cMatch, &rc); 114 if (rcRet2) 115 rcRet = rcRet2; 116 if (RT_FAILURE(rc)) 117 RTPrintf("tstDir-3: filter '%s' failed! rc=%Rrc\n", pszFilter2, rc); 118 if (!cMatch) 119 RTPrintf("tstDir-3: filter '%s' gave wrong result count! cMatch=%u\n", pszFilter2, cMatch); 120 121 if (!rcRet) 122 RTPrintf("tstDir-3: OK\n"); 98 123 return rcRet; 99 124 } 100
Note:
See TracChangeset
for help on using the changeset viewer.