VirtualBox

source: vbox/trunk/src/VBox/Runtime/testcase/tstDir-3.cpp@ 28267

Last change on this file since 28267 was 26163, checked in by vboxsync, 15 years ago

PDM: s/pUsbReg/pReg/g (2nd try, backed out r57176)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.7 KB
Line 
1/* $Id: tstDir-3.cpp 26163 2010-02-02 18:58:33Z vboxsync $ */
2/** @file
3 * IPRT Testcase - Directory listing & filtering (no parameters needed).
4 */
5
6/*
7 * Copyright (C) 2006-2008 Sun Microsystems, Inc.
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 *
26 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
27 * Clara, CA 95054 USA or visit http://www.sun.com if you need
28 * additional information or have any questions.
29 */
30
31#include <iprt/dir.h>
32#include <iprt/path.h>
33#include <iprt/stream.h>
34#include <iprt/err.h>
35#include <iprt/initterm.h>
36#include <iprt/string.h>
37
38static int tstDirOpenFiltered(const char *pszFilter, unsigned *pcFilesMatch, int *pRc)
39{
40 int rcRet = 0;
41 unsigned cFilesMatch = 0;
42 PRTDIR pDir;
43 int rc = RTDirOpenFiltered(&pDir, pszFilter, RTDIRFILTER_WINNT);
44 if (RT_SUCCESS(rc))
45 {
46 for (;;)
47 {
48 RTDIRENTRY DirEntry;
49 rc = RTDirRead(pDir, &DirEntry, NULL);
50 if (RT_FAILURE(rc))
51 break;
52 cFilesMatch++;
53 }
54
55 if (rc != VERR_NO_MORE_FILES)
56 {
57 RTPrintf("tstDir-3: Enumeration '%s' failed! rc=%Rrc\n", pszFilter, rc);
58 rcRet = 1;
59 }
60
61 /* close up */
62 rc = RTDirClose(pDir);
63 if (RT_FAILURE(rc))
64 {
65 RTPrintf("tstDir-3: Failed to close dir '%s'! rc=%Rrc\n", pszFilter, rc);
66 rcRet = 1;
67 }
68 }
69 else
70 {
71 RTPrintf("tstDir-3: Failed to open '%s', rc=%Rrc\n", pszFilter, rc);
72 rcRet = 1;
73 }
74
75 *pcFilesMatch = cFilesMatch;
76 *pRc = rc;
77 return rcRet;
78}
79
80int main(int argc, char **argv)
81{
82 int rcRet = 0;
83 int rcRet2;
84 int rc;
85 unsigned cMatch;
86 RTR3Init();
87
88 const char *pszTestDir = ".";
89
90 char *pszFilter1 = NULL;
91 rc = RTStrAPrintf(&pszFilter1, "%s%c%s", pszTestDir, RTPATH_SLASH, "xyxzxq*");
92 if (RT_FAILURE(rc))
93 {
94 RTPrintf("tstDir-3: cannot create non-match filter! rc=%Rrc\n", rc);
95 return 1;
96 }
97
98 char *pszFilter2 = NULL;
99 rc = RTStrAPrintf(&pszFilter2, "%s%c%s", pszTestDir, RTPATH_SLASH, "*");
100 if (RT_FAILURE(rc))
101 {
102 RTPrintf("tstDir-3: cannot create match filter! rc=%Rrc\n", rc);
103 return 1;
104 }
105
106 rcRet2 = tstDirOpenFiltered(pszFilter1, &cMatch, &rc);
107 if (rcRet2)
108 rcRet = rcRet2;
109 if (RT_FAILURE(rc))
110 RTPrintf("tstDir-3: filter '%s' failed! rc=%Rrc\n", pszFilter1, rc);
111 if (cMatch)
112 RTPrintf("tstDir-3: filter '%s' gave wrong result count! cMatch=%u\n", pszFilter1, cMatch);
113
114 rcRet2 = tstDirOpenFiltered(pszFilter2, &cMatch, &rc);
115 if (rcRet2)
116 rcRet = rcRet2;
117 if (RT_FAILURE(rc))
118 RTPrintf("tstDir-3: filter '%s' failed! rc=%Rrc\n", pszFilter2, rc);
119 if (!cMatch)
120 RTPrintf("tstDir-3: filter '%s' gave wrong result count! cMatch=%u\n", pszFilter2, cMatch);
121
122 if (!rcRet)
123 RTPrintf("tstDir-3: OK\n");
124 return rcRet;
125}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette