VirtualBox

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

Last change on this file since 32083 was 28800, checked in by vboxsync, 15 years ago

Automated rebranding to Oracle copyright/license strings via filemuncher

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.5 KB
Line 
1/* $Id: tstDir-3.cpp 28800 2010-04-27 08:22:32Z vboxsync $ */
2/** @file
3 * IPRT Testcase - Directory listing & filtering (no parameters needed).
4 */
5
6/*
7 * Copyright (C) 2006-2008 Oracle Corporation
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
27#include <iprt/dir.h>
28#include <iprt/path.h>
29#include <iprt/stream.h>
30#include <iprt/err.h>
31#include <iprt/initterm.h>
32#include <iprt/string.h>
33
34static int tstDirOpenFiltered(const char *pszFilter, unsigned *pcFilesMatch, int *pRc)
35{
36 int rcRet = 0;
37 unsigned cFilesMatch = 0;
38 PRTDIR pDir;
39 int rc = RTDirOpenFiltered(&pDir, pszFilter, RTDIRFILTER_WINNT);
40 if (RT_SUCCESS(rc))
41 {
42 for (;;)
43 {
44 RTDIRENTRY DirEntry;
45 rc = RTDirRead(pDir, &DirEntry, NULL);
46 if (RT_FAILURE(rc))
47 break;
48 cFilesMatch++;
49 }
50
51 if (rc != VERR_NO_MORE_FILES)
52 {
53 RTPrintf("tstDir-3: Enumeration '%s' failed! rc=%Rrc\n", pszFilter, rc);
54 rcRet = 1;
55 }
56
57 /* close up */
58 rc = RTDirClose(pDir);
59 if (RT_FAILURE(rc))
60 {
61 RTPrintf("tstDir-3: Failed to close dir '%s'! rc=%Rrc\n", pszFilter, rc);
62 rcRet = 1;
63 }
64 }
65 else
66 {
67 RTPrintf("tstDir-3: Failed to open '%s', rc=%Rrc\n", pszFilter, rc);
68 rcRet = 1;
69 }
70
71 *pcFilesMatch = cFilesMatch;
72 *pRc = rc;
73 return rcRet;
74}
75
76int main(int argc, char **argv)
77{
78 int rcRet = 0;
79 int rcRet2;
80 int rc;
81 unsigned cMatch;
82 RTR3Init();
83
84 const char *pszTestDir = ".";
85
86 char *pszFilter1 = NULL;
87 rc = RTStrAPrintf(&pszFilter1, "%s%c%s", pszTestDir, RTPATH_SLASH, "xyxzxq*");
88 if (RT_FAILURE(rc))
89 {
90 RTPrintf("tstDir-3: cannot create non-match filter! rc=%Rrc\n", rc);
91 return 1;
92 }
93
94 char *pszFilter2 = NULL;
95 rc = RTStrAPrintf(&pszFilter2, "%s%c%s", pszTestDir, RTPATH_SLASH, "*");
96 if (RT_FAILURE(rc))
97 {
98 RTPrintf("tstDir-3: cannot create match filter! rc=%Rrc\n", rc);
99 return 1;
100 }
101
102 rcRet2 = tstDirOpenFiltered(pszFilter1, &cMatch, &rc);
103 if (rcRet2)
104 rcRet = rcRet2;
105 if (RT_FAILURE(rc))
106 RTPrintf("tstDir-3: filter '%s' failed! rc=%Rrc\n", pszFilter1, rc);
107 if (cMatch)
108 RTPrintf("tstDir-3: filter '%s' gave wrong result count! cMatch=%u\n", pszFilter1, cMatch);
109
110 rcRet2 = tstDirOpenFiltered(pszFilter2, &cMatch, &rc);
111 if (rcRet2)
112 rcRet = rcRet2;
113 if (RT_FAILURE(rc))
114 RTPrintf("tstDir-3: filter '%s' failed! rc=%Rrc\n", pszFilter2, rc);
115 if (!cMatch)
116 RTPrintf("tstDir-3: filter '%s' gave wrong result count! cMatch=%u\n", pszFilter2, cMatch);
117
118 if (!rcRet)
119 RTPrintf("tstDir-3: OK\n");
120 return rcRet;
121}
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