author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Fri, 19 Feb 2010 23:40:16 +0200 | |
branch | RCL_3 |
changeset 4 | 3b1da2848fc7 |
parent 3 | 41300fa6a67c |
child 13 | c0432d11811c |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the test suite of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
|
24 |
** In addition, as a special exception, Nokia gives you certain additional |
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
||
42 |
||
43 |
#include <QtTest/QtTest> |
|
44 |
#include <qplatformdefs.h> |
|
45 |
||
46 |
#include <QAbstractFileEngine> |
|
47 |
#include <QFSFileEngine> |
|
48 |
#include <QCoreApplication> |
|
49 |
#include <QDebug> |
|
50 |
#include <QDir> |
|
51 |
#include <QFile> |
|
52 |
#include <QFileInfo> |
|
53 |
#if !defined(Q_OS_WINCE) && !defined(Q_OS_SYMBIAN) |
|
54 |
#include <QHostInfo> |
|
55 |
#endif |
|
56 |
#include <QProcess> |
|
57 |
#ifndef Q_OS_WIN |
|
58 |
# include <sys/types.h> |
|
59 |
# include <unistd.h> |
|
60 |
#endif |
|
61 |
#ifdef Q_OS_MAC |
|
62 |
# include <sys/mount.h> |
|
63 |
#elif defined(Q_OS_LINUX) |
|
64 |
# include <sys/vfs.h> |
|
65 |
#elif defined(Q_OS_FREEBSD) |
|
66 |
# include <sys/param.h> |
|
67 |
# include <sys/mount.h> |
|
68 |
#elif defined(Q_OS_IRIX) |
|
69 |
# include <sys/statfs.h> |
|
70 |
#elif defined(Q_OS_WINCE) |
|
71 |
# include <qplatformdefs.h> |
|
72 |
# include <private/qfsfileengine_p.h> |
|
73 |
#endif |
|
74 |
||
75 |
#include <stdio.h> |
|
76 |
#include "../network-settings.h" |
|
77 |
||
78 |
#if defined(Q_OS_SYMBIAN) |
|
79 |
# define SRCDIR "" |
|
80 |
#endif |
|
81 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
82 |
#ifndef STDIN_FILENO |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
83 |
#define STDIN_FILENO 0 |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
84 |
#endif |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
85 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
86 |
#ifndef STDOUT_FILENO |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
87 |
#define STDOUT_FILENO 1 |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
88 |
#endif |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
89 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
90 |
#ifndef STDERR_FILENO |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
91 |
#define STDERR_FILENO 2 |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
92 |
#endif |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
93 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
94 |
#ifndef QT_OPEN_BINARY |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
95 |
#define QT_OPEN_BINARY 0 |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
96 |
#endif |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
97 |
|
0 | 98 |
Q_DECLARE_METATYPE(QFile::FileError) |
99 |
||
100 |
//TESTED_CLASS= |
|
101 |
//TESTED_FILES= |
|
102 |
||
103 |
class tst_QFile : public QObject |
|
104 |
{ |
|
105 |
Q_OBJECT |
|
106 |
||
107 |
public: |
|
108 |
tst_QFile(); |
|
109 |
virtual ~tst_QFile(); |
|
110 |
||
111 |
||
112 |
public slots: |
|
113 |
void init(); |
|
114 |
void cleanup(); |
|
115 |
private slots: |
|
116 |
void initTestCase(); |
|
117 |
void cleanupTestCase(); |
|
118 |
void exists(); |
|
119 |
void open_data(); |
|
120 |
void open(); |
|
121 |
void openUnbuffered(); |
|
122 |
void size_data(); |
|
123 |
void size(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
124 |
void sizeNoExist(); |
0 | 125 |
void seek(); |
126 |
void setSize(); |
|
127 |
void setSizeSeek(); |
|
128 |
void atEnd(); |
|
129 |
void readLine(); |
|
130 |
void readLine2(); |
|
131 |
void readLineNullInLine(); |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
132 |
void readAll_data(); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
133 |
void readAll(); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
134 |
void readAllBuffer(); |
0 | 135 |
void readAllStdin(); |
136 |
void readLineStdin(); |
|
137 |
void readLineStdin_lineByLine(); |
|
138 |
void text(); |
|
139 |
void missingEndOfLine(); |
|
140 |
void readBlock(); |
|
141 |
void getch(); |
|
142 |
void ungetChar(); |
|
143 |
void createFile(); |
|
144 |
void append(); |
|
145 |
void permissions_data(); |
|
146 |
void permissions(); |
|
147 |
void setPermissions(); |
|
148 |
void copy(); |
|
149 |
void copyAfterFail(); |
|
150 |
void copyRemovesTemporaryFile() const; |
|
151 |
void copyShouldntOverwrite(); |
|
152 |
void copyFallback(); |
|
153 |
void link(); |
|
154 |
void linkToDir(); |
|
155 |
void absolutePathLinkToRelativePath(); |
|
156 |
void readBrokenLink(); |
|
157 |
void readTextFile_data(); |
|
158 |
void readTextFile(); |
|
159 |
void readTextFile2(); |
|
160 |
void writeTextFile_data(); |
|
161 |
void writeTextFile(); |
|
162 |
/* void largeFileSupport(); */ |
|
163 |
#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) |
|
164 |
void largeUncFileSupport(); |
|
165 |
#endif |
|
166 |
void tailFile(); |
|
167 |
void flush(); |
|
168 |
void bufferedRead(); |
|
169 |
void isSequential(); |
|
170 |
void encodeName(); |
|
171 |
void truncate(); |
|
172 |
void seekToPos(); |
|
173 |
void FILEReadWrite(); |
|
174 |
void i18nFileName_data(); |
|
175 |
void i18nFileName(); |
|
176 |
void longFileName_data(); |
|
177 |
void longFileName(); |
|
178 |
void fileEngineHandler(); |
|
179 |
void useQFileInAFileHandler(); |
|
180 |
void getCharFF(); |
|
181 |
void remove_and_exists(); |
|
182 |
void removeOpenFile(); |
|
183 |
void fullDisk(); |
|
184 |
void writeLargeDataBlock_data(); |
|
185 |
void writeLargeDataBlock(); |
|
186 |
void readFromWriteOnlyFile(); |
|
187 |
void writeToReadOnlyFile(); |
|
188 |
void virtualFile(); |
|
189 |
void textFile(); |
|
190 |
void rename_data(); |
|
191 |
void rename(); |
|
192 |
void renameWithAtEndSpecialFile() const; |
|
193 |
void renameFallback(); |
|
194 |
void renameMultiple(); |
|
195 |
void appendAndRead(); |
|
196 |
void miscWithUncPathAsCurrentDir(); |
|
197 |
void standarderror(); |
|
198 |
void handle(); |
|
199 |
||
200 |
void readEof_data(); |
|
201 |
void readEof(); |
|
202 |
||
203 |
void map_data(); |
|
204 |
void map(); |
|
205 |
void mapResource_data(); |
|
206 |
void mapResource(); |
|
207 |
void mapOpenMode_data(); |
|
208 |
void mapOpenMode(); |
|
209 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
210 |
void openStandardStreams(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
211 |
|
0 | 212 |
// --- Task related tests below this line |
213 |
void task167217(); |
|
214 |
||
215 |
void openDirectory(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
216 |
void writeNothing(); |
0 | 217 |
|
218 |
public: |
|
219 |
// disabled this test for the moment... it hangs |
|
220 |
void invalidFile_data(); |
|
221 |
void invalidFile(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
222 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
223 |
private: |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
224 |
enum FileType { OpenQFile, OpenFd, OpenStream }; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
225 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
226 |
void openStandardStreamsFileDescriptors(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
227 |
void openStandardStreamsBufferedStreams(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
228 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
229 |
bool openFd(QFile &file, QIODevice::OpenMode mode) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
230 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
231 |
int fdMode = QT_OPEN_LARGEFILE | QT_OPEN_BINARY; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
232 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
233 |
// File will be truncated if in Write mode. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
234 |
if (mode & QIODevice::WriteOnly) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
235 |
fdMode |= QT_OPEN_WRONLY | QT_OPEN_TRUNC; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
236 |
if (mode & QIODevice::ReadOnly) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
237 |
fdMode |= QT_OPEN_RDONLY; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
238 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
239 |
fd_ = QT_OPEN(qPrintable(file.fileName()), fdMode); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
240 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
241 |
return (-1 != fd_) && file.open(fd_, mode); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
242 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
243 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
244 |
bool openStream(QFile &file, QIODevice::OpenMode mode) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
245 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
246 |
char const *streamMode = ""; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
247 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
248 |
// File will be truncated if in Write mode. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
249 |
if (mode & QIODevice::WriteOnly) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
250 |
streamMode = "wb+"; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
251 |
else if (mode & QIODevice::ReadOnly) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
252 |
streamMode = "rb"; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
253 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
254 |
stream_ = QT_FOPEN(qPrintable(file.fileName()), streamMode); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
255 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
256 |
return stream_ && file.open(stream_, mode); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
257 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
258 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
259 |
bool openFile(QFile &file, QIODevice::OpenMode mode, FileType type = OpenQFile) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
260 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
261 |
if (mode & QIODevice::WriteOnly && !file.exists()) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
262 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
263 |
// Make sure the file exists |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
264 |
QFile createFile(file.fileName()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
265 |
if (!createFile.open(QIODevice::ReadWrite)) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
266 |
return false; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
267 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
268 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
269 |
// Note: openFd and openStream will truncate the file if write mode. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
270 |
switch (type) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
271 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
272 |
case OpenQFile: |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
273 |
return file.open(mode); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
274 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
275 |
case OpenFd: |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
276 |
return openFd(file, mode); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
277 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
278 |
case OpenStream: |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
279 |
return openStream(file, mode); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
280 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
281 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
282 |
return false; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
283 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
284 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
285 |
void closeFile(QFile &file) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
286 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
287 |
file.close(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
288 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
289 |
if (-1 != fd_) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
290 |
QT_CLOSE(fd_); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
291 |
if (stream_) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
292 |
::fclose(stream_); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
293 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
294 |
fd_ = -1; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
295 |
stream_ = 0; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
296 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
297 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
298 |
int fd_; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
299 |
FILE *stream_; |
0 | 300 |
}; |
301 |
||
302 |
tst_QFile::tst_QFile() |
|
303 |
{ |
|
304 |
} |
|
305 |
||
306 |
tst_QFile::~tst_QFile() |
|
307 |
{ |
|
308 |
||
309 |
} |
|
310 |
||
311 |
void tst_QFile::init() |
|
312 |
{ |
|
313 |
// TODO: Add initialization code here. |
|
314 |
// This will be executed immediately before each test is run. |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
315 |
fd_ = -1; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
316 |
stream_ = 0; |
0 | 317 |
} |
318 |
||
319 |
void tst_QFile::cleanup() |
|
320 |
{ |
|
321 |
// TODO: Add cleanup code here. |
|
322 |
// This will be executed immediately after each test is run. |
|
323 |
||
324 |
// for copyFallback() |
|
325 |
if (QFile::exists("file-copy-destination.txt")) { |
|
326 |
QFile::setPermissions("file-copy-destination.txt", |
|
327 |
QFile::ReadOwner | QFile::WriteOwner); |
|
328 |
QFile::remove("file-copy-destination.txt"); |
|
329 |
} |
|
330 |
||
331 |
// for renameFallback() |
|
332 |
QFile::remove("file-rename-destination.txt"); |
|
333 |
||
334 |
// for copyAfterFail() |
|
335 |
QFile::remove("file-to-be-copied.txt"); |
|
336 |
QFile::remove("existing-file.txt"); |
|
337 |
QFile::remove("copied-file-1.txt"); |
|
338 |
QFile::remove("copied-file-2.txt"); |
|
339 |
||
340 |
// for renameMultiple() |
|
341 |
QFile::remove("file-to-be-renamed.txt"); |
|
342 |
QFile::remove("existing-file.txt"); |
|
343 |
QFile::remove("file-renamed-once.txt"); |
|
344 |
QFile::remove("file-renamed-twice.txt"); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
345 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
346 |
if (-1 != fd_) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
347 |
QT_CLOSE(fd_); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
348 |
if (stream_) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
349 |
::fclose(stream_); |
0 | 350 |
} |
351 |
||
352 |
void tst_QFile::initTestCase() |
|
353 |
{ |
|
354 |
QFile::remove("noreadfile"); |
|
355 |
||
356 |
// create a file and make it read-only |
|
357 |
QFile file("readonlyfile"); |
|
358 |
file.open(QFile::WriteOnly); |
|
359 |
file.write("a", 1); |
|
360 |
file.close(); |
|
361 |
file.setPermissions(QFile::ReadOwner); |
|
362 |
||
363 |
// create another file and make it not readable |
|
364 |
file.setFileName("noreadfile"); |
|
365 |
file.open(QFile::WriteOnly); |
|
366 |
file.write("b", 1); |
|
367 |
file.close(); |
|
368 |
file.setPermissions(0); |
|
369 |
} |
|
370 |
||
371 |
void tst_QFile::cleanupTestCase() |
|
372 |
{ |
|
373 |
// clean up the files we created |
|
374 |
QFile::remove("readonlyfile"); |
|
375 |
QFile::remove("noreadfile"); |
|
376 |
QFile::remove("myLink.lnk"); |
|
377 |
QFile::remove("appendme.txt"); |
|
378 |
QFile::remove("createme.txt"); |
|
379 |
QFile::remove("file.txt"); |
|
380 |
QFile::remove("genfile.txt"); |
|
381 |
QFile::remove("seekToPos.txt"); |
|
382 |
QFile::remove("setsizeseek.txt"); |
|
383 |
QFile::remove("stdfile.txt"); |
|
384 |
QFile::remove("textfile.txt"); |
|
385 |
QFile::remove("truncate.txt"); |
|
386 |
QFile::remove("winfile.txt"); |
|
387 |
QFile::remove("writeonlyfile"); |
|
388 |
QFile::remove("largeblockfile.txt"); |
|
389 |
QFile::remove("tst_qfile_copy.cpp"); |
|
390 |
QFile::remove("nullinline.txt"); |
|
391 |
QFile::remove("myLink2.lnk"); |
|
392 |
QFile::remove("resources"); |
|
393 |
QFile::remove("qfile_map_testfile"); |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
394 |
QFile::remove("readAllBuffer.txt"); |
0 | 395 |
} |
396 |
||
397 |
//------------------------------------------ |
|
398 |
// The 'testfile' is currently just a |
|
399 |
// testfile. The path of this file, the |
|
400 |
// attributes and the contents itself |
|
401 |
// will be changed as far as we have a |
|
402 |
// proper way to handle files in the |
|
403 |
// testing enviroment. |
|
404 |
//------------------------------------------ |
|
405 |
||
406 |
void tst_QFile::exists() |
|
407 |
{ |
|
408 |
QFile f( SRCDIR "testfile.txt" ); |
|
409 |
QCOMPARE( f.exists(), (bool)TRUE ); |
|
410 |
||
411 |
QFile file("nobodyhassuchafile"); |
|
412 |
file.remove(); |
|
413 |
QVERIFY(!file.exists()); |
|
414 |
||
415 |
QFile file2("nobodyhassuchafile"); |
|
416 |
QVERIFY(file2.open(QIODevice::WriteOnly)); |
|
417 |
file2.close(); |
|
418 |
||
419 |
QVERIFY(file.exists()); |
|
420 |
||
421 |
QVERIFY(file.open(QIODevice::WriteOnly)); |
|
422 |
file.close(); |
|
423 |
QVERIFY(file.exists()); |
|
424 |
||
425 |
file.remove(); |
|
426 |
QVERIFY(!file.exists()); |
|
427 |
||
428 |
#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) |
|
429 |
QFile unc("//" + QtNetworkSettings::winServerName() + "/testshare/readme.txt"); |
|
430 |
QVERIFY(unc.exists()); |
|
431 |
#endif |
|
432 |
} |
|
433 |
||
434 |
void tst_QFile::open_data() |
|
435 |
{ |
|
436 |
QTest::addColumn<QString>("filename"); |
|
437 |
QTest::addColumn<int>("mode"); |
|
438 |
QTest::addColumn<bool>("ok"); |
|
439 |
QTest::addColumn<QFile::FileError>("status"); |
|
440 |
||
441 |
#ifdef Q_OS_MAC |
|
442 |
static const QString denied("Operation not permitted"); |
|
443 |
#else |
|
444 |
static const QString denied("Permission denied"); |
|
445 |
#endif |
|
446 |
QTest::newRow( "exist_readOnly" ) |
|
447 |
<< QString(SRCDIR "testfile.txt") << int(QIODevice::ReadOnly) |
|
448 |
<< (bool)TRUE << QFile::NoError; |
|
449 |
||
450 |
QTest::newRow( "exist_writeOnly" ) |
|
451 |
<< QString("readonlyfile") |
|
452 |
<< int(QIODevice::WriteOnly) |
|
453 |
<< (bool)FALSE |
|
454 |
<< QFile::OpenError; |
|
455 |
||
456 |
QTest::newRow( "exist_append" ) |
|
457 |
<< QString("readonlyfile") << int(QIODevice::Append) |
|
458 |
<< (bool)FALSE << QFile::OpenError; |
|
459 |
||
460 |
QTest::newRow( "nonexist_readOnly" ) |
|
461 |
<< QString("nonExist.txt") << int(QIODevice::ReadOnly) |
|
462 |
<< (bool)FALSE << QFile::OpenError; |
|
463 |
||
464 |
QTest::newRow("emptyfile") |
|
465 |
<< QString("") |
|
466 |
<< int(QIODevice::ReadOnly) |
|
467 |
<< (bool)FALSE |
|
468 |
<< QFile::OpenError; |
|
469 |
||
470 |
QTest::newRow("nullfile") << QString() << int(QIODevice::ReadOnly) << (bool)FALSE |
|
471 |
<< QFile::OpenError; |
|
472 |
||
473 |
QTest::newRow("two-dots") << QString(SRCDIR "two.dots.file") << int(QIODevice::ReadOnly) << (bool)TRUE |
|
474 |
<< QFile::NoError; |
|
475 |
||
476 |
QTest::newRow("readonlyfile") << QString("readonlyfile") << int(QIODevice::WriteOnly) |
|
477 |
<< (bool)FALSE << QFile::OpenError; |
|
478 |
QTest::newRow("noreadfile") << QString("noreadfile") << int(QIODevice::ReadOnly) |
|
479 |
<< (bool)FALSE << QFile::OpenError; |
|
480 |
#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) |
|
481 |
QTest::newRow("//./PhysicalDrive0") << QString("//./PhysicalDrive0") << int(QIODevice::ReadOnly) |
|
482 |
<< (bool)TRUE << QFile::NoError; |
|
483 |
QTest::newRow("uncFile") << "//" + QtNetworkSettings::winServerName() + "/testsharewritable/test.pri" << int(QIODevice::ReadOnly) |
|
484 |
<< true << QFile::NoError; |
|
485 |
#endif |
|
486 |
} |
|
487 |
||
488 |
void tst_QFile::open() |
|
489 |
{ |
|
490 |
QFETCH( QString, filename ); |
|
491 |
QFETCH( int, mode ); |
|
492 |
||
493 |
QFile f( filename ); |
|
494 |
||
495 |
QFETCH( bool, ok ); |
|
496 |
||
497 |
#if defined(Q_OS_SYMBIAN) |
|
498 |
if (qstrcmp(QTest::currentDataTag(), "noreadfile") == 0) |
|
499 |
QSKIP("Symbian does not support non-readable files", SkipSingle); |
|
500 |
#elif defined(Q_OS_UNIX) |
|
501 |
if (::getuid() == 0) |
|
502 |
// root and Chuck Norris don't care for file permissions. Skip. |
|
503 |
QSKIP("Running this test as root doesn't make sense", SkipAll); |
|
504 |
#endif |
|
505 |
||
506 |
#if defined(Q_OS_WIN32) || defined(Q_OS_WINCE) |
|
507 |
QEXPECT_FAIL("noreadfile", "Windows does not currently support non-readable files.", Abort); |
|
508 |
#endif |
|
509 |
if (filename.isEmpty()) |
|
510 |
QTest::ignoreMessage(QtWarningMsg, "QFSFileEngine::open: No file name specified"); |
|
511 |
||
512 |
QCOMPARE(f.open( QIODevice::OpenMode(mode) ), ok); |
|
513 |
||
514 |
QTEST( f.error(), "status" ); |
|
515 |
} |
|
516 |
||
517 |
void tst_QFile::openUnbuffered() |
|
518 |
{ |
|
519 |
QFile file(SRCDIR "testfile.txt"); |
|
520 |
QVERIFY(file.open(QIODevice::ReadOnly | QIODevice::Unbuffered)); |
|
521 |
char c = '\0'; |
|
522 |
QVERIFY(file.seek(1)); |
|
523 |
QCOMPARE(file.pos(), qint64(1)); |
|
524 |
QVERIFY(file.getChar(&c)); |
|
525 |
QCOMPARE(file.pos(), qint64(2)); |
|
526 |
char d = '\0'; |
|
527 |
QVERIFY(file.seek(3)); |
|
528 |
QCOMPARE(file.pos(), qint64(3)); |
|
529 |
QVERIFY(file.getChar(&d)); |
|
530 |
QCOMPARE(file.pos(), qint64(4)); |
|
531 |
QVERIFY(file.seek(1)); |
|
532 |
QCOMPARE(file.pos(), qint64(1)); |
|
533 |
char c2 = '\0'; |
|
534 |
QVERIFY(file.getChar(&c2)); |
|
535 |
QCOMPARE(file.pos(), qint64(2)); |
|
536 |
QVERIFY(file.seek(3)); |
|
537 |
QCOMPARE(file.pos(), qint64(3)); |
|
538 |
char d2 = '\0'; |
|
539 |
QVERIFY(file.getChar(&d2)); |
|
540 |
QCOMPARE(file.pos(), qint64(4)); |
|
541 |
QCOMPARE(c, c2); |
|
542 |
QCOMPARE(d, d2); |
|
543 |
QCOMPARE(c, '-'); |
|
544 |
QCOMPARE(d, '-'); |
|
545 |
} |
|
546 |
||
547 |
void tst_QFile::size_data() |
|
548 |
{ |
|
549 |
QTest::addColumn<QString>("filename"); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
550 |
QTest::addColumn<qint64>("size"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
551 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
552 |
QTest::newRow( "exist01" ) << QString(SRCDIR "testfile.txt") << (qint64)245; |
0 | 553 |
#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) |
554 |
// Only test UNC on Windows./ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
555 |
QTest::newRow("unc") << "//" + QString(QtNetworkSettings::winServerName() + "/testsharewritable/test.pri") << (qint64)34; |
0 | 556 |
#endif |
557 |
} |
|
558 |
||
559 |
void tst_QFile::size() |
|
560 |
{ |
|
561 |
QFETCH( QString, filename ); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
562 |
QFETCH( qint64, size ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
563 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
564 |
#ifdef Q_WS_WINCE |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
565 |
filename = QFileInfo(filename).absoluteFilePath(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
566 |
#endif |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
567 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
568 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
569 |
QFile f( filename ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
570 |
QCOMPARE( f.size(), size ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
571 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
572 |
QVERIFY( f.open(QIODevice::ReadOnly) ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
573 |
QCOMPARE( f.size(), size ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
574 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
575 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
576 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
577 |
QFile f; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
578 |
FILE* stream = QT_FOPEN(filename.toLocal8Bit().constData(), "rb"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
579 |
QVERIFY( stream ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
580 |
QVERIFY( f.open(stream, QIODevice::ReadOnly) ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
581 |
QCOMPARE( f.size(), size ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
582 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
583 |
f.close(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
584 |
fclose(stream); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
585 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
586 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
587 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
588 |
#ifdef Q_WS_WINCE |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
589 |
QSKIP("Currently low level file I/O not well supported on Windows CE", SkipSingle); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
590 |
#endif |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
591 |
QFile f; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
592 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
593 |
int fd = QT_OPEN(filename.toLocal8Bit().constData(), QT_OPEN_RDONLY); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
594 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
595 |
QVERIFY( fd != -1 ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
596 |
QVERIFY( f.open(fd, QIODevice::ReadOnly) ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
597 |
QCOMPARE( f.size(), size ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
598 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
599 |
f.close(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
600 |
QT_CLOSE(fd); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
601 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
602 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
603 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
604 |
void tst_QFile::sizeNoExist() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
605 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
606 |
QFile file("nonexist01"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
607 |
QVERIFY( !file.exists() ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
608 |
QCOMPARE( file.size(), (qint64)0 ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
609 |
QVERIFY( !file.open(QIODevice::ReadOnly) ); |
0 | 610 |
} |
611 |
||
612 |
void tst_QFile::seek() |
|
613 |
{ |
|
614 |
QFile::remove("newfile.txt"); |
|
615 |
QFile file("newfile.txt"); |
|
616 |
file.open(QIODevice::WriteOnly); |
|
617 |
QCOMPARE(file.size(), qint64(0)); |
|
618 |
QCOMPARE(file.pos(), qint64(0)); |
|
619 |
QVERIFY(file.seek(10)); |
|
620 |
QCOMPARE(file.pos(), qint64(10)); |
|
621 |
QCOMPARE(file.size(), qint64(0)); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
622 |
file.close(); |
0 | 623 |
QFile::remove("newfile.txt"); |
624 |
} |
|
625 |
||
626 |
void tst_QFile::setSize() |
|
627 |
{ |
|
628 |
DEPENDS_ON( "size" ); |
|
629 |
||
630 |
if ( QFile::exists( "createme.txt" ) ) |
|
631 |
QFile::remove( "createme.txt" ); |
|
632 |
QVERIFY( !QFile::exists( "createme.txt" ) ); |
|
633 |
||
634 |
QFile f("createme.txt"); |
|
635 |
QVERIFY(f.open(QIODevice::Truncate | QIODevice::ReadWrite)); |
|
636 |
f.putChar('a'); |
|
637 |
||
638 |
f.seek(0); |
|
639 |
char c = '\0'; |
|
640 |
f.getChar(&c); |
|
641 |
QCOMPARE(c, 'a'); |
|
642 |
||
643 |
QCOMPARE(f.size(), (qlonglong)1); |
|
644 |
bool ok = f.resize(99); |
|
645 |
QVERIFY(ok); |
|
646 |
QCOMPARE(f.size(), (qlonglong)99); |
|
647 |
||
648 |
f.seek(0); |
|
649 |
c = '\0'; |
|
650 |
f.getChar(&c); |
|
651 |
QCOMPARE(c, 'a'); |
|
652 |
||
653 |
QVERIFY(f.resize(1)); |
|
654 |
QCOMPARE(f.size(), (qlonglong)1); |
|
655 |
||
656 |
f.seek(0); |
|
657 |
c = '\0'; |
|
658 |
f.getChar(&c); |
|
659 |
QCOMPARE(c, 'a'); |
|
660 |
||
661 |
f.close(); |
|
662 |
||
663 |
QCOMPARE(f.size(), (qlonglong)1); |
|
664 |
QVERIFY(f.resize(100)); |
|
665 |
QCOMPARE(f.size(), (qlonglong)100); |
|
666 |
QVERIFY(f.resize(50)); |
|
667 |
QCOMPARE(f.size(), (qlonglong)50); |
|
668 |
} |
|
669 |
||
670 |
void tst_QFile::setSizeSeek() |
|
671 |
{ |
|
672 |
QFile::remove("setsizeseek.txt"); |
|
673 |
QFile f("setsizeseek.txt"); |
|
674 |
QVERIFY(f.open(QFile::WriteOnly)); |
|
675 |
f.write("ABCD"); |
|
676 |
||
677 |
QCOMPARE(f.pos(), qint64(4)); |
|
678 |
f.resize(2); |
|
679 |
QCOMPARE(f.pos(), qint64(2)); |
|
680 |
f.resize(4); |
|
681 |
QCOMPARE(f.pos(), qint64(2)); |
|
682 |
f.resize(0); |
|
683 |
QCOMPARE(f.pos(), qint64(0)); |
|
684 |
f.resize(4); |
|
685 |
QCOMPARE(f.pos(), qint64(0)); |
|
686 |
||
687 |
f.seek(3); |
|
688 |
QCOMPARE(f.pos(), qint64(3)); |
|
689 |
f.resize(2); |
|
690 |
QCOMPARE(f.pos(), qint64(2)); |
|
691 |
} |
|
692 |
||
693 |
void tst_QFile::atEnd() |
|
694 |
{ |
|
695 |
QFile f( SRCDIR "testfile.txt" ); |
|
696 |
QVERIFY(f.open( QIODevice::ReadOnly )); |
|
697 |
||
698 |
int size = f.size(); |
|
699 |
f.seek( size ); |
|
700 |
||
701 |
bool end = f.atEnd(); |
|
702 |
f.close(); |
|
703 |
QCOMPARE( end, (bool)TRUE ); |
|
704 |
} |
|
705 |
||
706 |
void tst_QFile::readLine() |
|
707 |
{ |
|
708 |
QFile f( SRCDIR "testfile.txt" ); |
|
709 |
QVERIFY(f.open( QIODevice::ReadOnly )); |
|
710 |
||
711 |
int i = 0; |
|
712 |
char p[128]; |
|
713 |
int foo; |
|
714 |
while ( (foo=f.readLine( p, 128 )) > 0 ) { |
|
715 |
++i; |
|
716 |
if ( i == 5 ) { |
|
717 |
QCOMPARE( p[0], 'T' ); |
|
718 |
QCOMPARE( p[3], 's' ); |
|
719 |
QCOMPARE( p[11], 'i' ); |
|
720 |
} |
|
721 |
} |
|
722 |
f.close(); |
|
723 |
QCOMPARE( i, 6 ); |
|
724 |
} |
|
725 |
||
726 |
void tst_QFile::readLine2() |
|
727 |
{ |
|
728 |
QFile f( SRCDIR "testfile.txt" ); |
|
729 |
f.open( QIODevice::ReadOnly ); |
|
730 |
||
731 |
char p[128]; |
|
732 |
QCOMPARE(f.readLine(p, 60), qlonglong(59)); |
|
733 |
QCOMPARE(f.readLine(p, 60), qlonglong(59)); |
|
734 |
memset(p, '@', sizeof(p)); |
|
735 |
QCOMPARE(f.readLine(p, 60), qlonglong(59)); |
|
736 |
||
737 |
QCOMPARE(p[57], '-'); |
|
738 |
QCOMPARE(p[58], '\n'); |
|
739 |
QCOMPARE(p[59], '\0'); |
|
740 |
QCOMPARE(p[60], '@'); |
|
741 |
} |
|
742 |
||
743 |
void tst_QFile::readLineNullInLine() |
|
744 |
{ |
|
745 |
QFile::remove("nullinline.txt"); |
|
746 |
QFile file("nullinline.txt"); |
|
747 |
QVERIFY(file.open(QIODevice::ReadWrite)); |
|
748 |
QVERIFY(file.write("linewith\0null\nanotherline\0withnull\n\0\nnull\0", 42) > 0); |
|
749 |
QVERIFY(file.flush()); |
|
750 |
file.reset(); |
|
751 |
||
752 |
QCOMPARE(file.readLine(), QByteArray("linewith\0null\n", 14)); |
|
753 |
QCOMPARE(file.readLine(), QByteArray("anotherline\0withnull\n", 21)); |
|
754 |
QCOMPARE(file.readLine(), QByteArray("\0\n", 2)); |
|
755 |
QCOMPARE(file.readLine(), QByteArray("null\0", 5)); |
|
756 |
QCOMPARE(file.readLine(), QByteArray()); |
|
757 |
} |
|
758 |
||
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
759 |
void tst_QFile::readAll_data() |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
760 |
{ |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
761 |
QTest::addColumn<bool>("textMode"); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
762 |
QTest::addColumn<QString>("fileName"); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
763 |
QTest::newRow( "TextMode unixfile" ) << true << SRCDIR "testfile.txt"; |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
764 |
QTest::newRow( "BinaryMode unixfile" ) << false << SRCDIR "testfile.txt"; |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
765 |
QTest::newRow( "TextMode dosfile" ) << true << SRCDIR "dosfile.txt"; |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
766 |
QTest::newRow( "BinaryMode dosfile" ) << false << SRCDIR "dosfile.txt"; |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
767 |
QTest::newRow( "TextMode bigfile" ) << true << SRCDIR "tst_qfile.cpp"; |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
768 |
QTest::newRow( "BinaryMode bigfile" ) << false << SRCDIR "tst_qfile.cpp"; |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
769 |
QVERIFY(QFile(SRCDIR "tst_qfile.cpp").size() > 64*1024); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
770 |
} |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
771 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
772 |
void tst_QFile::readAll() |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
773 |
{ |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
774 |
QFETCH( bool, textMode ); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
775 |
QFETCH( QString, fileName ); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
776 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
777 |
QFile file(fileName); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
778 |
if (textMode) |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
779 |
QVERIFY(file.open(QFile::Text | QFile::ReadOnly)); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
780 |
else |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
781 |
QVERIFY(file.open(QFile::ReadOnly)); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
782 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
783 |
QByteArray a = file.readAll(); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
784 |
file.reset(); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
785 |
QVERIFY(file.pos() == 0); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
786 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
787 |
QVERIFY(file.bytesAvailable() > 7); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
788 |
QByteArray b = file.read(1); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
789 |
char x; |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
790 |
file.getChar(&x); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
791 |
b.append(x); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
792 |
b.append(file.read(5)); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
793 |
b.append(file.readAll()); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
794 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
795 |
QCOMPARE(a, b); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
796 |
} |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
797 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
798 |
void tst_QFile::readAllBuffer() |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
799 |
{ |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
800 |
QString fileName = QLatin1String("readAllBuffer.txt"); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
801 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
802 |
QFile::remove(fileName); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
803 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
804 |
QFile writer(fileName); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
805 |
QFile reader(fileName); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
806 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
807 |
QByteArray data1("This is arguably a very simple text."); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
808 |
QByteArray data2("This is surely not as simple a test."); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
809 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
810 |
QVERIFY( writer.open(QIODevice::ReadWrite | QIODevice::Unbuffered) ); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
811 |
QVERIFY( reader.open(QIODevice::ReadOnly) ); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
812 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
813 |
QCOMPARE( writer.write(data1), qint64(data1.size()) ); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
814 |
QVERIFY( writer.seek(0) ); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
815 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
816 |
QByteArray result; |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
817 |
result = reader.read(18); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
818 |
QCOMPARE( result.size(), 18 ); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
819 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
820 |
QCOMPARE( writer.write(data2), qint64(data2.size()) ); // new data, old version buffered in reader |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
821 |
QCOMPARE( writer.write(data2), qint64(data2.size()) ); // new data, unbuffered in reader |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
822 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
823 |
result += reader.readAll(); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
824 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
825 |
QCOMPARE( result, data1 + data2 ); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
826 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
827 |
QFile::remove(fileName); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
828 |
} |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
829 |
|
0 | 830 |
void tst_QFile::readAllStdin() |
831 |
{ |
|
832 |
#if defined(Q_OS_WINCE) || defined(Q_OS_SYMBIAN) |
|
833 |
QSKIP("Currently no stdin/out supported for Windows CE or Symbian", SkipAll); |
|
834 |
#endif |
|
835 |
#if defined(QT_NO_PROCESS) |
|
836 |
QSKIP("Qt was compiled with QT_NO_PROCESS", SkipAll); |
|
837 |
#else |
|
838 |
QByteArray lotsOfData(1024, '@'); // 10 megs |
|
839 |
||
840 |
QProcess process; |
|
841 |
process.start("stdinprocess/stdinprocess all"); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
842 |
QVERIFY( process.waitForStarted() ); |
0 | 843 |
for (int i = 0; i < 5; ++i) { |
844 |
QTest::qWait(1000); |
|
845 |
process.write(lotsOfData); |
|
846 |
while (process.bytesToWrite() > 0) { |
|
847 |
QVERIFY(process.waitForBytesWritten()); |
|
848 |
} |
|
849 |
} |
|
850 |
||
851 |
process.closeWriteChannel(); |
|
852 |
process.waitForFinished(); |
|
853 |
QCOMPARE(process.readAll().size(), lotsOfData.size() * 5); |
|
854 |
#endif |
|
855 |
} |
|
856 |
||
857 |
void tst_QFile::readLineStdin() |
|
858 |
{ |
|
859 |
#if defined(Q_OS_WINCE) || defined(Q_OS_SYMBIAN) |
|
860 |
QSKIP("Currently no stdin/out supported for Windows CE or Symbian", SkipAll); |
|
861 |
#endif |
|
862 |
#if defined(QT_NO_PROCESS) |
|
863 |
QSKIP("Qt was compiled with QT_NO_PROCESS", SkipAll); |
|
864 |
#else |
|
865 |
||
866 |
QByteArray lotsOfData(1024, '@'); // 10 megs |
|
867 |
for (int i = 0; i < lotsOfData.size(); ++i) { |
|
868 |
if ((i % 32) == 31) |
|
869 |
lotsOfData[i] = '\n'; |
|
870 |
else |
|
871 |
lotsOfData[i] = char('0' + i % 32); |
|
872 |
} |
|
873 |
||
874 |
for (int i = 0; i < 2; ++i) { |
|
875 |
QProcess process; |
|
876 |
process.start(QString("stdinprocess/stdinprocess line %1").arg(i), QIODevice::Text | QIODevice::ReadWrite); |
|
877 |
for (int i = 0; i < 5; ++i) { |
|
878 |
QTest::qWait(1000); |
|
879 |
process.write(lotsOfData); |
|
880 |
while (process.bytesToWrite() > 0) { |
|
881 |
QVERIFY(process.waitForBytesWritten()); |
|
882 |
} |
|
883 |
} |
|
884 |
||
885 |
process.closeWriteChannel(); |
|
886 |
QVERIFY(process.waitForFinished(5000)); |
|
887 |
||
888 |
QByteArray array = process.readAll(); |
|
889 |
QCOMPARE(array.size(), lotsOfData.size() * 5); |
|
890 |
for (int i = 0; i < array.size(); ++i) { |
|
891 |
if ((i % 32) == 31) |
|
892 |
QCOMPARE(char(array[i]), '\n'); |
|
893 |
else |
|
894 |
QCOMPARE(char(array[i]), char('0' + i % 32)); |
|
895 |
} |
|
896 |
} |
|
897 |
#endif |
|
898 |
} |
|
899 |
||
900 |
void tst_QFile::readLineStdin_lineByLine() |
|
901 |
{ |
|
902 |
#if defined(Q_OS_WINCE) || defined(Q_OS_SYMBIAN) |
|
903 |
QSKIP("Currently no stdin/out supported for Windows CE", SkipAll); |
|
904 |
#endif |
|
905 |
#if defined(QT_NO_PROCESS) |
|
906 |
QSKIP("Qt was compiled with QT_NO_PROCESS", SkipAll); |
|
907 |
#else |
|
908 |
for (int i = 0; i < 2; ++i) { |
|
909 |
QProcess process; |
|
910 |
process.start(QString("stdinprocess/stdinprocess line %1").arg(i), QIODevice::Text | QIODevice::ReadWrite); |
|
911 |
QVERIFY(process.waitForStarted()); |
|
912 |
||
913 |
for (int j = 0; j < 3; ++j) { |
|
914 |
QByteArray line = "line " + QByteArray::number(j) + "\n"; |
|
915 |
QCOMPARE(process.write(line), qint64(line.size())); |
|
916 |
QVERIFY(process.waitForBytesWritten(2000)); |
|
917 |
if (process.bytesAvailable() == 0) |
|
918 |
QVERIFY(process.waitForReadyRead(2000)); |
|
919 |
QCOMPARE(process.readAll(), line); |
|
920 |
} |
|
921 |
||
922 |
process.closeWriteChannel(); |
|
923 |
QVERIFY(process.waitForFinished(5000)); |
|
924 |
} |
|
925 |
#endif |
|
926 |
} |
|
927 |
||
928 |
void tst_QFile::text() |
|
929 |
{ |
|
930 |
// dosfile.txt is a binary CRLF file |
|
931 |
QFile file(SRCDIR "dosfile.txt"); |
|
932 |
QVERIFY(file.open(QFile::Text | QFile::ReadOnly)); |
|
933 |
QCOMPARE(file.readLine(), |
|
934 |
QByteArray("/dev/system/root / reiserfs acl,user_xattr 1 1\n")); |
|
935 |
QCOMPARE(file.readLine(), |
|
936 |
QByteArray("/dev/sda1 /boot ext3 acl,user_xattr 1 2\n")); |
|
937 |
file.ungetChar('\n'); |
|
938 |
file.ungetChar('2'); |
|
939 |
QCOMPARE(file.readLine().constData(), QByteArray("2\n").constData()); |
|
940 |
} |
|
941 |
||
942 |
void tst_QFile::missingEndOfLine() |
|
943 |
{ |
|
944 |
QFile file(SRCDIR "noendofline.txt"); |
|
945 |
QVERIFY(file.open(QFile::ReadOnly)); |
|
946 |
||
947 |
int nlines = 0; |
|
948 |
while (!file.atEnd()) { |
|
949 |
++nlines; |
|
950 |
file.readLine(); |
|
951 |
} |
|
952 |
||
953 |
QCOMPARE(nlines, 3); |
|
954 |
} |
|
955 |
||
956 |
void tst_QFile::readBlock() |
|
957 |
{ |
|
958 |
QFile f( SRCDIR "testfile.txt" ); |
|
959 |
f.open( QIODevice::ReadOnly ); |
|
960 |
||
961 |
int length = 0; |
|
962 |
char p[256]; |
|
963 |
length = f.read( p, 256 ); |
|
964 |
f.close(); |
|
965 |
QCOMPARE( length, 245 ); |
|
966 |
QCOMPARE( p[59], 'D' ); |
|
967 |
QCOMPARE( p[178], 'T' ); |
|
968 |
QCOMPARE( p[199], 'l' ); |
|
969 |
} |
|
970 |
||
971 |
void tst_QFile::getch() |
|
972 |
{ |
|
973 |
QFile f( SRCDIR "testfile.txt" ); |
|
974 |
f.open( QIODevice::ReadOnly ); |
|
975 |
||
976 |
char c; |
|
977 |
int i = 0; |
|
978 |
while (f.getChar(&c)) { |
|
979 |
QCOMPARE(f.pos(), qint64(i + 1)); |
|
980 |
if ( i == 59 ) |
|
981 |
QCOMPARE( c, 'D' ); |
|
982 |
++i; |
|
983 |
} |
|
984 |
f.close(); |
|
985 |
QCOMPARE( i, 245 ); |
|
986 |
} |
|
987 |
||
988 |
void tst_QFile::ungetChar() |
|
989 |
{ |
|
990 |
QFile f(SRCDIR "testfile.txt"); |
|
991 |
QVERIFY(f.open(QIODevice::ReadOnly)); |
|
992 |
||
993 |
QByteArray array = f.readLine(); |
|
994 |
QCOMPARE(array.constData(), "----------------------------------------------------------\n"); |
|
995 |
f.ungetChar('\n'); |
|
996 |
||
997 |
array = f.readLine(); |
|
998 |
QCOMPARE(array.constData(), "\n"); |
|
999 |
||
1000 |
f.ungetChar('\n'); |
|
1001 |
f.ungetChar('-'); |
|
1002 |
f.ungetChar('-'); |
|
1003 |
||
1004 |
array = f.readLine(); |
|
1005 |
QCOMPARE(array.constData(), "--\n"); |
|
1006 |
||
1007 |
QFile::remove("genfile.txt"); |
|
1008 |
QFile out("genfile.txt"); |
|
1009 |
QVERIFY(out.open(QIODevice::ReadWrite)); |
|
1010 |
out.write("123"); |
|
1011 |
out.seek(0); |
|
1012 |
QCOMPARE(out.readAll().constData(), "123"); |
|
1013 |
out.ungetChar('3'); |
|
1014 |
out.write("4"); |
|
1015 |
out.seek(0); |
|
1016 |
QCOMPARE(out.readAll().constData(), "124"); |
|
1017 |
out.ungetChar('4'); |
|
1018 |
out.ungetChar('2'); |
|
1019 |
out.ungetChar('1'); |
|
1020 |
char buf[3]; |
|
1021 |
QCOMPARE(out.read(buf, sizeof(buf)), qint64(3)); |
|
1022 |
QCOMPARE(buf[0], '1'); |
|
1023 |
QCOMPARE(buf[1], '2'); |
|
1024 |
QCOMPARE(buf[2], '4'); |
|
1025 |
} |
|
1026 |
||
1027 |
void tst_QFile::invalidFile_data() |
|
1028 |
{ |
|
1029 |
QTest::addColumn<QString>("fileName"); |
|
1030 |
#if !defined(Q_WS_WIN) && !defined(Q_OS_SYMBIAN) |
|
1031 |
QTest::newRow( "x11" ) << QString( "qwe//" ); |
|
1032 |
#else |
|
1033 |
QTest::newRow( "colon1" ) << QString( "fail:invalid" ); |
|
1034 |
QTest::newRow( "colon2" ) << QString( "f:ail:invalid" ); |
|
1035 |
QTest::newRow( "colon3" ) << QString( ":failinvalid" ); |
|
1036 |
QTest::newRow( "forwardslash" ) << QString( "fail/invalid" ); |
|
1037 |
QTest::newRow( "asterisk" ) << QString( "fail*invalid" ); |
|
1038 |
QTest::newRow( "questionmark" ) << QString( "fail?invalid" ); |
|
1039 |
QTest::newRow( "quote" ) << QString( "fail\"invalid" ); |
|
1040 |
QTest::newRow( "lt" ) << QString( "fail<invalid" ); |
|
1041 |
QTest::newRow( "gt" ) << QString( "fail>invalid" ); |
|
1042 |
QTest::newRow( "pipe" ) << QString( "fail|invalid" ); |
|
1043 |
#endif |
|
1044 |
} |
|
1045 |
||
1046 |
void tst_QFile::invalidFile() |
|
1047 |
{ |
|
1048 |
QFETCH( QString, fileName ); |
|
1049 |
QFile f( fileName ); |
|
1050 |
QVERIFY( !f.open( QIODevice::ReadWrite ) ); |
|
1051 |
} |
|
1052 |
||
1053 |
void tst_QFile::createFile() |
|
1054 |
{ |
|
1055 |
if ( QFile::exists( "createme.txt" ) ) |
|
1056 |
QFile::remove( "createme.txt" ); |
|
1057 |
QVERIFY( !QFile::exists( "createme.txt" ) ); |
|
1058 |
||
1059 |
QFile f( "createme.txt" ); |
|
1060 |
QVERIFY( f.open( QIODevice::WriteOnly ) ); |
|
1061 |
f.close(); |
|
1062 |
QVERIFY( QFile::exists( "createme.txt" ) ); |
|
1063 |
} |
|
1064 |
||
1065 |
void tst_QFile::append() |
|
1066 |
{ |
|
1067 |
const QString name("appendme.txt"); |
|
1068 |
if (QFile::exists(name)) |
|
1069 |
QFile::remove(name); |
|
1070 |
QVERIFY(!QFile::exists(name)); |
|
1071 |
||
1072 |
QFile f(name); |
|
1073 |
QVERIFY(f.open(QIODevice::WriteOnly | QIODevice::Truncate)); |
|
1074 |
f.putChar('a'); |
|
1075 |
f.close(); |
|
1076 |
||
1077 |
QVERIFY(f.open(QIODevice::Append)); |
|
1078 |
QVERIFY(f.pos() == 1); |
|
1079 |
f.putChar('a'); |
|
1080 |
f.close(); |
|
1081 |
QCOMPARE(int(f.size()), 2); |
|
1082 |
} |
|
1083 |
||
1084 |
void tst_QFile::permissions_data() |
|
1085 |
{ |
|
1086 |
QTest::addColumn<QString>("file"); |
|
1087 |
QTest::addColumn<uint>("perms"); |
|
1088 |
QTest::addColumn<bool>("expected"); |
|
1089 |
||
1090 |
QTest::newRow("data0") << QCoreApplication::instance()->applicationFilePath() << uint(QFile::ExeUser) << true; |
|
1091 |
QTest::newRow("data1") << SRCDIR "tst_qfile.cpp" << uint(QFile::ReadUser) << true; |
|
1092 |
// QTest::newRow("data2") << "tst_qfile.cpp" << int(QFile::WriteUser) << false; |
|
1093 |
QTest::newRow("resource1") << ":/tst_qfileinfo/resources/file1.ext1" << uint(QFile::ReadUser) << true; |
|
1094 |
QTest::newRow("resource2") << ":/tst_qfileinfo/resources/file1.ext1" << uint(QFile::WriteUser) << false; |
|
1095 |
QTest::newRow("resource3") << ":/tst_qfileinfo/resources/file1.ext1" << uint(QFile::ExeUser) << false; |
|
1096 |
} |
|
1097 |
||
1098 |
void tst_QFile::permissions() |
|
1099 |
{ |
|
1100 |
#if defined(Q_OS_SYMBIAN) |
|
1101 |
if (qstrcmp(QTest::currentDataTag(), "data0") == 0) |
|
1102 |
QSKIP("Symbian does not have execution permissions", SkipSingle); |
|
1103 |
#endif |
|
1104 |
QFETCH(QString, file); |
|
1105 |
QFETCH(uint, perms); |
|
1106 |
QFETCH(bool, expected); |
|
1107 |
QFile f(file); |
|
1108 |
QCOMPARE(((f.permissions() & perms) == QFile::Permissions(perms)), expected); |
|
1109 |
} |
|
1110 |
||
1111 |
void tst_QFile::setPermissions() |
|
1112 |
{ |
|
1113 |
DEPENDS_ON( "permissions" ); //if that doesn't work... |
|
1114 |
||
1115 |
if ( QFile::exists( "createme.txt" ) ) |
|
1116 |
QFile::remove( "createme.txt" ); |
|
1117 |
QVERIFY( !QFile::exists( "createme.txt" ) ); |
|
1118 |
||
1119 |
QFile f("createme.txt"); |
|
1120 |
QVERIFY(f.open(QIODevice::WriteOnly | QIODevice::Truncate)); |
|
1121 |
f.putChar('a'); |
|
1122 |
f.close(); |
|
1123 |
||
1124 |
QFile::Permissions perms(QFile::WriteUser | QFile::ReadUser); |
|
1125 |
QVERIFY(f.setPermissions(perms)); |
|
1126 |
QVERIFY((f.permissions() & perms) == perms); |
|
1127 |
||
1128 |
} |
|
1129 |
||
1130 |
void tst_QFile::copy() |
|
1131 |
{ |
|
1132 |
QFile::setPermissions("tst_qfile_copy.cpp", QFile::WriteUser); |
|
1133 |
QFile::remove("tst_qfile_copy.cpp"); |
|
1134 |
QFile::remove("test2"); |
|
1135 |
QVERIFY(QFile::copy(SRCDIR "tst_qfile.cpp", "tst_qfile_copy.cpp")); |
|
1136 |
QFile in1(SRCDIR "tst_qfile.cpp"), in2("tst_qfile_copy.cpp"); |
|
1137 |
QVERIFY(in1.open(QFile::ReadOnly)); |
|
1138 |
QVERIFY(in2.open(QFile::ReadOnly)); |
|
1139 |
QByteArray data1 = in1.readAll(), data2 = in2.readAll(); |
|
1140 |
QCOMPARE(data1, data2); |
|
1141 |
QFile::remove( "main_copy.cpp" ); |
|
1142 |
||
1143 |
QFile::copy(QDir::currentPath(), QDir::currentPath() + QLatin1String("/test2")); |
|
1144 |
} |
|
1145 |
||
1146 |
void tst_QFile::copyAfterFail() |
|
1147 |
{ |
|
1148 |
QFile file1("file-to-be-copied.txt"); |
|
1149 |
QFile file2("existing-file.txt"); |
|
1150 |
||
1151 |
QVERIFY(file1.open(QIODevice::ReadWrite) && "(test-precondition)"); |
|
1152 |
QVERIFY(file2.open(QIODevice::ReadWrite) && "(test-precondition)"); |
|
1153 |
file2.close(); |
|
1154 |
QVERIFY(!QFile::exists("copied-file-1.txt") && "(test-precondition)"); |
|
1155 |
QVERIFY(!QFile::exists("copied-file-2.txt") && "(test-precondition)"); |
|
1156 |
||
1157 |
QVERIFY(!file1.copy("existing-file.txt")); |
|
1158 |
QCOMPARE(file1.error(), QFile::CopyError); |
|
1159 |
||
1160 |
QVERIFY(file1.copy("copied-file-1.txt")); |
|
1161 |
QVERIFY(!file1.isOpen()); |
|
1162 |
QCOMPARE(file1.error(), QFile::NoError); |
|
1163 |
||
1164 |
QVERIFY(!file1.copy("existing-file.txt")); |
|
1165 |
QCOMPARE(file1.error(), QFile::CopyError); |
|
1166 |
||
1167 |
QVERIFY(file1.copy("copied-file-2.txt")); |
|
1168 |
QVERIFY(!file1.isOpen()); |
|
1169 |
QCOMPARE(file1.error(), QFile::NoError); |
|
1170 |
||
1171 |
QVERIFY(QFile::exists("copied-file-1.txt")); |
|
1172 |
QVERIFY(QFile::exists("copied-file-2.txt")); |
|
1173 |
||
1174 |
QVERIFY(QFile::remove("file-to-be-copied.txt") && "(test-cleanup)"); |
|
1175 |
QVERIFY(QFile::remove("existing-file.txt") && "(test-cleanup)"); |
|
1176 |
QVERIFY(QFile::remove("copied-file-1.txt") && "(test-cleanup)"); |
|
1177 |
QVERIFY(QFile::remove("copied-file-2.txt") && "(test-cleanup)"); |
|
1178 |
} |
|
1179 |
||
1180 |
void tst_QFile::copyRemovesTemporaryFile() const |
|
1181 |
{ |
|
1182 |
const QString newName(QLatin1String("copyRemovesTemporaryFile")); |
|
1183 |
QVERIFY(QFile::copy(SRCDIR "forCopying.txt", newName)); |
|
1184 |
||
1185 |
QVERIFY(!QFile::exists(QLatin1String( SRCDIR "qt_temp.XXXXXX"))); |
|
1186 |
QVERIFY(QFile::remove(newName)); |
|
1187 |
} |
|
1188 |
||
1189 |
void tst_QFile::copyShouldntOverwrite() |
|
1190 |
{ |
|
1191 |
// Copy should not overwrite existing files. |
|
1192 |
QFile::remove("tst_qfile.cpy"); |
|
1193 |
QFile file(SRCDIR "tst_qfile.cpp"); |
|
1194 |
QVERIFY(file.copy("tst_qfile.cpy")); |
|
1195 |
#if defined(Q_OS_SYMBIAN) |
|
1196 |
bool ok = QFile::setPermissions("tst_qfile.cpy", QFile::WriteUser); |
|
1197 |
#else |
|
1198 |
bool ok = QFile::setPermissions("tst_qfile.cpy", QFile::WriteOther); |
|
1199 |
#endif |
|
1200 |
QVERIFY(ok); |
|
1201 |
QVERIFY(!file.copy("tst_qfile.cpy")); |
|
1202 |
QFile::remove("tst_qfile.cpy"); |
|
1203 |
} |
|
1204 |
||
1205 |
void tst_QFile::copyFallback() |
|
1206 |
{ |
|
1207 |
// Using a resource file to trigger QFile::copy's fallback handling |
|
1208 |
QFile file(":/copy-fallback.qrc"); |
|
1209 |
QFile::remove("file-copy-destination.txt"); |
|
1210 |
||
1211 |
QVERIFY2(file.exists(), "test precondition"); |
|
1212 |
QVERIFY2(!QFile::exists("file-copy-destination.txt"), "test precondition"); |
|
1213 |
||
1214 |
// Fallback copy of closed file. |
|
1215 |
QVERIFY(file.copy("file-copy-destination.txt")); |
|
1216 |
QVERIFY(QFile::exists("file-copy-destination.txt")); |
|
1217 |
QVERIFY(!file.isOpen()); |
|
1218 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1219 |
#ifdef Q_WS_WINCE |
0 | 1220 |
// Need to reset permissions on Windows to be able to delete |
1221 |
QVERIFY(QFile::setPermissions("file-copy-destination.txt", |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1222 |
QFile::WriteOther)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1223 |
#else |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1224 |
// Need to reset permissions on Windows to be able to delete |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1225 |
QVERIFY(QFile::setPermissions("file-copy-destination.txt", |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1226 |
QFile::ReadOwner | QFile::WriteOwner)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1227 |
#endif |
0 | 1228 |
QVERIFY(QFile::remove("file-copy-destination.txt")); |
1229 |
||
1230 |
// Fallback copy of open file. |
|
1231 |
QVERIFY(file.open(QIODevice::ReadOnly)); |
|
1232 |
QVERIFY(file.copy("file-copy-destination.txt")); |
|
1233 |
QVERIFY(QFile::exists("file-copy-destination.txt")); |
|
1234 |
QVERIFY(!file.isOpen()); |
|
1235 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1236 |
file.close(); |
0 | 1237 |
QFile::remove("file-copy-destination.txt"); |
1238 |
} |
|
1239 |
||
1240 |
#ifdef Q_OS_WIN |
|
1241 |
#include <objbase.h> |
|
1242 |
#include <shlobj.h> |
|
1243 |
#endif |
|
1244 |
||
1245 |
#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) |
|
1246 |
static QString getWorkingDirectoryForLink(const QString &linkFileName) |
|
1247 |
{ |
|
1248 |
bool neededCoInit = false; |
|
1249 |
QString ret; |
|
1250 |
||
1251 |
IShellLink *psl; |
|
1252 |
HRESULT hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (void **)&psl); |
|
1253 |
if (hres == CO_E_NOTINITIALIZED) { // COM was not initialized |
|
1254 |
neededCoInit = true; |
|
1255 |
CoInitialize(NULL); |
|
1256 |
hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (void **)&psl); |
|
1257 |
} |
|
1258 |
||
1259 |
if (SUCCEEDED(hres)) { // Get pointer to the IPersistFile interface. |
|
1260 |
IPersistFile *ppf; |
|
1261 |
hres = psl->QueryInterface(IID_IPersistFile, (LPVOID *)&ppf); |
|
1262 |
if (SUCCEEDED(hres)) { |
|
1263 |
hres = ppf->Load((LPOLESTR)linkFileName.utf16(), STGM_READ); |
|
1264 |
//The original path of the link is retrieved. If the file/folder |
|
1265 |
//was moved, the return value still have the old path. |
|
1266 |
if(SUCCEEDED(hres)) { |
|
1267 |
wchar_t szGotPath[MAX_PATH]; |
|
1268 |
if (psl->GetWorkingDirectory(szGotPath, MAX_PATH) == NOERROR) |
|
1269 |
ret = QString::fromWCharArray(szGotPath); |
|
1270 |
} |
|
1271 |
ppf->Release(); |
|
1272 |
} |
|
1273 |
psl->Release(); |
|
1274 |
} |
|
1275 |
||
1276 |
if (neededCoInit) { |
|
1277 |
CoUninitialize(); |
|
1278 |
} |
|
1279 |
||
1280 |
return ret; |
|
1281 |
} |
|
1282 |
#endif |
|
1283 |
||
1284 |
void tst_QFile::link() |
|
1285 |
{ |
|
1286 |
QFile::remove("myLink.lnk"); |
|
1287 |
QFileInfo info1("tst_qfile.cpp"); |
|
1288 |
QVERIFY(QFile::link("tst_qfile.cpp", "myLink.lnk")); |
|
1289 |
QFileInfo info2("myLink.lnk"); |
|
1290 |
QVERIFY(info2.isSymLink()); |
|
1291 |
QCOMPARE(info2.symLinkTarget(), info1.absoluteFilePath()); |
|
1292 |
||
1293 |
#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) |
|
1294 |
QString wd = getWorkingDirectoryForLink(info2.absoluteFilePath()); |
|
1295 |
QCOMPARE(QDir::fromNativeSeparators(wd), info1.absolutePath()); |
|
1296 |
#endif |
|
1297 |
QVERIFY(QFile::remove(info2.absoluteFilePath())); |
|
1298 |
} |
|
1299 |
||
1300 |
void tst_QFile::linkToDir() |
|
1301 |
{ |
|
1302 |
#if defined(Q_OS_SYMBIAN) |
|
1303 |
QSKIP("Symbian does not support linking to directories", SkipAll); |
|
1304 |
#endif |
|
1305 |
QFile::remove("myLinkToDir.lnk"); |
|
1306 |
QDir dir; |
|
1307 |
dir.mkdir("myDir"); |
|
1308 |
QFileInfo info1("myDir"); |
|
1309 |
QVERIFY(QFile::link("myDir", "myLinkToDir.lnk")); |
|
1310 |
QFileInfo info2("myLinkToDir.lnk"); |
|
1311 |
#if !(defined Q_OS_HPUX && defined(__ia64)) |
|
1312 |
// absurd HP-UX filesystem bug on gravlaks - checking if a symlink |
|
1313 |
// resolves or not alters the file system to make the broken symlink |
|
1314 |
// later fail... |
|
1315 |
QVERIFY(info2.isSymLink()); |
|
1316 |
#endif |
|
1317 |
QCOMPARE(info2.symLinkTarget(), info1.absoluteFilePath()); |
|
1318 |
QVERIFY(QFile::remove(info2.absoluteFilePath())); |
|
1319 |
QFile::remove("myLinkToDir.lnk"); |
|
1320 |
dir.rmdir("myDir"); |
|
1321 |
} |
|
1322 |
||
1323 |
void tst_QFile::absolutePathLinkToRelativePath() |
|
1324 |
{ |
|
1325 |
QFile::remove("myDir/test.txt"); |
|
1326 |
QFile::remove("myDir/myLink.lnk"); |
|
1327 |
QDir dir; |
|
1328 |
dir.mkdir("myDir"); |
|
1329 |
QFile("myDir/test.txt").open(QFile::WriteOnly); |
|
1330 |
||
1331 |
#ifdef Q_OS_WIN |
|
1332 |
QVERIFY(QFile::link("test.txt", "myDir/myLink.lnk")); |
|
1333 |
#else |
|
1334 |
QVERIFY(QFile::link("myDir/test.txt", "myDir/myLink.lnk")); |
|
1335 |
#endif |
|
1336 |
QEXPECT_FAIL("", "Symlinking using relative paths is currently different on Windows and Unix/Symbian", Continue); |
|
1337 |
QCOMPARE(QFileInfo(QFile(QFileInfo("myDir/myLink.lnk").absoluteFilePath()).symLinkTarget()).absoluteFilePath(), |
|
1338 |
QFileInfo("myDir/test.txt").absoluteFilePath()); |
|
1339 |
||
1340 |
QFile::remove("myDir/test.txt"); |
|
1341 |
QFile::remove("myDir/myLink.lnk"); |
|
1342 |
dir.rmdir("myDir"); |
|
1343 |
} |
|
1344 |
||
1345 |
void tst_QFile::readBrokenLink() |
|
1346 |
{ |
|
1347 |
QFile::remove("myLink2.lnk"); |
|
1348 |
QFileInfo info1("file12"); |
|
1349 |
#if defined(Q_OS_SYMBIAN) |
|
1350 |
// In Symbian can't link to nonexisting file directly, so create the file temporarily |
|
1351 |
QFile tempFile("file12"); |
|
1352 |
tempFile.open(QIODevice::WriteOnly); |
|
1353 |
tempFile.link("myLink2.lnk"); |
|
1354 |
tempFile.remove(); |
|
1355 |
#else |
|
1356 |
QVERIFY(QFile::link("file12", "myLink2.lnk")); |
|
1357 |
#endif |
|
1358 |
QFileInfo info2("myLink2.lnk"); |
|
1359 |
QVERIFY(info2.isSymLink()); |
|
1360 |
QCOMPARE(info2.symLinkTarget(), info1.absoluteFilePath()); |
|
1361 |
QVERIFY(QFile::remove(info2.absoluteFilePath())); |
|
1362 |
||
1363 |
#if !defined(Q_OS_SYMBIAN) |
|
1364 |
QVERIFY(QFile::link("ole/..", "myLink2.lnk")); |
|
1365 |
QCOMPARE(QFileInfo("myLink2.lnk").symLinkTarget(), QDir::currentPath()); |
|
1366 |
#endif |
|
1367 |
} |
|
1368 |
||
1369 |
void tst_QFile::readTextFile_data() |
|
1370 |
{ |
|
1371 |
QTest::addColumn<QByteArray>("in"); |
|
1372 |
QTest::addColumn<QByteArray>("out"); |
|
1373 |
||
1374 |
QTest::newRow("empty") << QByteArray() << QByteArray(); |
|
1375 |
QTest::newRow("a") << QByteArray("a") << QByteArray("a"); |
|
1376 |
QTest::newRow("a\\rb") << QByteArray("a\rb") << QByteArray("ab"); |
|
1377 |
QTest::newRow("\\n") << QByteArray("\n") << QByteArray("\n"); |
|
1378 |
QTest::newRow("\\r\\n") << QByteArray("\r\n") << QByteArray("\n"); |
|
1379 |
QTest::newRow("\\r") << QByteArray("\r") << QByteArray(); |
|
1380 |
QTest::newRow("twolines") << QByteArray("Hello\r\nWorld\r\n") << QByteArray("Hello\nWorld\n"); |
|
1381 |
QTest::newRow("twolines no endline") << QByteArray("Hello\r\nWorld") << QByteArray("Hello\nWorld"); |
|
1382 |
} |
|
1383 |
||
1384 |
void tst_QFile::readTextFile() |
|
1385 |
{ |
|
1386 |
QFETCH(QByteArray, in); |
|
1387 |
QFETCH(QByteArray, out); |
|
1388 |
||
1389 |
QFile winfile("winfile.txt"); |
|
1390 |
QVERIFY(winfile.open(QFile::WriteOnly | QFile::Truncate)); |
|
1391 |
winfile.write(in); |
|
1392 |
winfile.close(); |
|
1393 |
||
1394 |
QVERIFY(winfile.open(QFile::ReadOnly)); |
|
1395 |
QCOMPARE(winfile.readAll(), in); |
|
1396 |
winfile.close(); |
|
1397 |
||
1398 |
QVERIFY(winfile.open(QFile::ReadOnly | QFile::Text)); |
|
1399 |
QCOMPARE(winfile.readAll(), out); |
|
1400 |
} |
|
1401 |
||
1402 |
void tst_QFile::readTextFile2() |
|
1403 |
{ |
|
1404 |
{ |
|
1405 |
QFile file(SRCDIR "testlog.txt"); |
|
1406 |
QVERIFY(file.open(QIODevice::ReadOnly)); |
|
1407 |
file.read(4097); |
|
1408 |
} |
|
1409 |
||
1410 |
{ |
|
1411 |
QFile file(SRCDIR "testlog.txt"); |
|
1412 |
QVERIFY(file.open(QIODevice::ReadOnly | QIODevice::Text)); |
|
1413 |
file.read(4097); |
|
1414 |
} |
|
1415 |
} |
|
1416 |
||
1417 |
void tst_QFile::writeTextFile_data() |
|
1418 |
{ |
|
1419 |
QTest::addColumn<QByteArray>("in"); |
|
1420 |
||
1421 |
QTest::newRow("empty") << QByteArray(); |
|
1422 |
QTest::newRow("a") << QByteArray("a"); |
|
1423 |
QTest::newRow("a\\rb") << QByteArray("a\rb"); |
|
1424 |
QTest::newRow("\\n") << QByteArray("\n"); |
|
1425 |
QTest::newRow("\\r\\n") << QByteArray("\r\n"); |
|
1426 |
QTest::newRow("\\r") << QByteArray("\r"); |
|
1427 |
QTest::newRow("twolines crlf") << QByteArray("Hello\r\nWorld\r\n"); |
|
1428 |
QTest::newRow("twolines crlf no endline") << QByteArray("Hello\r\nWorld"); |
|
1429 |
QTest::newRow("twolines lf") << QByteArray("Hello\nWorld\n"); |
|
1430 |
QTest::newRow("twolines lf no endline") << QByteArray("Hello\nWorld"); |
|
1431 |
QTest::newRow("mixed") << QByteArray("this\nis\r\na\nmixed\r\nfile\n"); |
|
1432 |
} |
|
1433 |
||
1434 |
void tst_QFile::writeTextFile() |
|
1435 |
{ |
|
1436 |
QFETCH(QByteArray, in); |
|
1437 |
||
1438 |
QFile file("textfile.txt"); |
|
1439 |
QVERIFY(file.open(QFile::WriteOnly | QFile::Truncate | QFile::Text)); |
|
1440 |
QByteArray out = in; |
|
1441 |
#ifdef Q_OS_WIN |
|
1442 |
out.replace('\n', "\r\n"); |
|
1443 |
#endif |
|
1444 |
QCOMPARE(file.write(in), qlonglong(in.size())); |
|
1445 |
file.close(); |
|
1446 |
||
1447 |
file.open(QFile::ReadOnly); |
|
1448 |
QCOMPARE(file.readAll(), out); |
|
1449 |
} |
|
1450 |
||
1451 |
#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) |
|
1452 |
void tst_QFile::largeUncFileSupport() |
|
1453 |
{ |
|
1454 |
qint64 size = Q_INT64_C(8589934592); |
|
1455 |
qint64 dataOffset = Q_INT64_C(8589914592); |
|
1456 |
QByteArray knownData("LargeFile content at offset 8589914592"); |
|
1457 |
QString largeFile("//" + QtNetworkSettings::winServerName() + "/testsharelargefile/file.bin"); |
|
1458 |
||
1459 |
{ |
|
1460 |
// 1) Native file handling. |
|
1461 |
QFile file(largeFile); |
|
1462 |
QCOMPARE(file.size(), size); |
|
1463 |
QVERIFY(file.open(QIODevice::ReadOnly)); |
|
1464 |
QCOMPARE(file.size(), size); |
|
1465 |
QVERIFY(file.seek(dataOffset)); |
|
1466 |
QCOMPARE(file.read(knownData.size()), knownData); |
|
1467 |
} |
|
1468 |
{ |
|
1469 |
// 2) stdlib file handling. |
|
1470 |
#if _MSC_VER <= 1310 |
|
1471 |
QSKIP("platform SDK for MSVC 2003 does not support large files", SkipAll); |
|
1472 |
#endif |
|
1473 |
QFile file; |
|
1474 |
FILE *fh = fopen(QFile::encodeName(largeFile).data(), "rb"); |
|
1475 |
QVERIFY(file.open(fh, QIODevice::ReadOnly)); |
|
1476 |
QCOMPARE(file.size(), size); |
|
1477 |
QVERIFY(file.seek(dataOffset)); |
|
1478 |
QCOMPARE(file.read(knownData.size()), knownData); |
|
1479 |
fclose(fh); |
|
1480 |
} |
|
1481 |
{ |
|
1482 |
// 3) stdio file handling. |
|
1483 |
QFile file; |
|
1484 |
FILE *fh = fopen(QFile::encodeName(largeFile).data(), "rb"); |
|
1485 |
int fd = int(_fileno(fh)); |
|
1486 |
QVERIFY(file.open(fd, QIODevice::ReadOnly)); |
|
1487 |
QCOMPARE(file.size(), size); |
|
1488 |
QVERIFY(file.seek(dataOffset)); |
|
1489 |
QCOMPARE(file.read(knownData.size()), knownData); |
|
1490 |
fclose(fh); |
|
1491 |
} |
|
1492 |
} |
|
1493 |
#endif |
|
1494 |
||
1495 |
void tst_QFile::tailFile() |
|
1496 |
{ |
|
1497 |
QSKIP("File change notifications are so far unsupported.", SkipAll); |
|
1498 |
||
1499 |
QFile file("tail.txt"); |
|
1500 |
QVERIFY(file.open(QFile::WriteOnly | QFile::Append)); |
|
1501 |
||
1502 |
QFile tailFile("tail.txt"); |
|
1503 |
QVERIFY(tailFile.open(QFile::ReadOnly)); |
|
1504 |
tailFile.seek(file.size()); |
|
1505 |
||
1506 |
QSignalSpy readSignal(&tailFile, SIGNAL(readyRead())); |
|
1507 |
||
1508 |
file.write("", 1); |
|
1509 |
||
1510 |
QTestEventLoop::instance().enterLoop(5); |
|
1511 |
||
1512 |
QVERIFY(!QTestEventLoop::instance().timeout()); |
|
1513 |
QCOMPARE(readSignal.count(), 1); |
|
1514 |
} |
|
1515 |
||
1516 |
void tst_QFile::flush() |
|
1517 |
{ |
|
1518 |
QString fileName("stdfile.txt"); |
|
1519 |
||
1520 |
QFile::remove(fileName); |
|
1521 |
||
1522 |
{ |
|
1523 |
QFile file(fileName); |
|
1524 |
QVERIFY(file.open(QFile::WriteOnly)); |
|
1525 |
QCOMPARE(file.write("abc", 3),qint64(3)); |
|
1526 |
} |
|
1527 |
||
1528 |
{ |
|
1529 |
QFile file(fileName); |
|
1530 |
QVERIFY(file.open(QFile::WriteOnly | QFile::Append)); |
|
1531 |
QCOMPARE(file.pos(), qlonglong(3)); |
|
1532 |
QCOMPARE(file.write("def", 3), qlonglong(3)); |
|
1533 |
QCOMPARE(file.pos(), qlonglong(6)); |
|
1534 |
} |
|
1535 |
||
1536 |
{ |
|
1537 |
QFile file("stdfile.txt"); |
|
1538 |
QVERIFY(file.open(QFile::ReadOnly)); |
|
1539 |
QCOMPARE(file.readAll(), QByteArray("abcdef")); |
|
1540 |
} |
|
1541 |
||
1542 |
QFile::remove(fileName); |
|
1543 |
} |
|
1544 |
||
1545 |
void tst_QFile::bufferedRead() |
|
1546 |
{ |
|
1547 |
QFile::remove("stdfile.txt"); |
|
1548 |
||
1549 |
QFile file("stdfile.txt"); |
|
1550 |
QVERIFY(file.open(QFile::WriteOnly)); |
|
1551 |
file.write("abcdef"); |
|
1552 |
file.close(); |
|
1553 |
||
1554 |
#if defined(Q_OS_WINCE) |
|
1555 |
FILE *stdFile = fopen((QCoreApplication::applicationDirPath() + "/stdfile.txt").toAscii() , "r"); |
|
1556 |
#else |
|
1557 |
FILE *stdFile = fopen("stdfile.txt", "r"); |
|
1558 |
#endif |
|
1559 |
QVERIFY(stdFile); |
|
1560 |
char c; |
|
1561 |
QCOMPARE(int(fread(&c, 1, 1, stdFile)), 1); |
|
1562 |
QCOMPARE(c, 'a'); |
|
1563 |
QCOMPARE(int(ftell(stdFile)), 1); |
|
1564 |
||
1565 |
{ |
|
1566 |
QFile file; |
|
1567 |
QVERIFY(file.open(stdFile, QFile::ReadOnly)); |
|
1568 |
QCOMPARE(file.pos(), qlonglong(1)); |
|
1569 |
QCOMPARE(file.read(&c, 1), qlonglong(1)); |
|
1570 |
QCOMPARE(c, 'b'); |
|
1571 |
QCOMPARE(file.pos(), qlonglong(2)); |
|
1572 |
} |
|
1573 |
||
1574 |
fclose(stdFile); |
|
1575 |
} |
|
1576 |
||
1577 |
void tst_QFile::isSequential() |
|
1578 |
{ |
|
1579 |
#if defined (Q_OS_WIN) || defined(Q_OS_SYMBIAN) |
|
1580 |
QSKIP("Unix only test.", SkipAll); |
|
1581 |
#endif |
|
1582 |
||
1583 |
QFile zero("/dev/null"); |
|
1584 |
QVERIFY(zero.open(QFile::ReadOnly)); |
|
1585 |
QVERIFY(zero.isSequential()); |
|
1586 |
} |
|
1587 |
||
1588 |
void tst_QFile::encodeName() |
|
1589 |
{ |
|
1590 |
QCOMPARE(QFile::encodeName(QString::null), QByteArray()); |
|
1591 |
} |
|
1592 |
||
1593 |
void tst_QFile::truncate() |
|
1594 |
{ |
|
1595 |
for (int i = 0; i < 2; ++i) { |
|
1596 |
QFile file("truncate.txt"); |
|
1597 |
QVERIFY(file.open(QFile::WriteOnly)); |
|
1598 |
file.write(QByteArray(200, '@')); |
|
1599 |
file.close(); |
|
1600 |
||
1601 |
QVERIFY(file.open((i ? QFile::WriteOnly : QFile::ReadWrite) | QFile::Truncate)); |
|
1602 |
file.write(QByteArray(100, '$')); |
|
1603 |
file.close(); |
|
1604 |
||
1605 |
QVERIFY(file.open(QFile::ReadOnly)); |
|
1606 |
QCOMPARE(file.readAll(), QByteArray(100, '$')); |
|
1607 |
} |
|
1608 |
} |
|
1609 |
||
1610 |
void tst_QFile::seekToPos() |
|
1611 |
{ |
|
1612 |
{ |
|
1613 |
QFile file("seekToPos.txt"); |
|
1614 |
QVERIFY(file.open(QFile::WriteOnly)); |
|
1615 |
file.write("a\r\nb\r\nc\r\n"); |
|
1616 |
file.flush(); |
|
1617 |
} |
|
1618 |
||
1619 |
QFile file("seekToPos.txt"); |
|
1620 |
QVERIFY(file.open(QFile::ReadOnly | QFile::Text)); |
|
1621 |
file.seek(1); |
|
1622 |
char c; |
|
1623 |
QVERIFY(file.getChar(&c)); |
|
1624 |
QCOMPARE(c, '\n'); |
|
1625 |
||
1626 |
QCOMPARE(file.pos(), qint64(3)); |
|
1627 |
file.seek(file.pos()); |
|
1628 |
QCOMPARE(file.pos(), qint64(3)); |
|
1629 |
||
1630 |
file.seek(1); |
|
1631 |
file.seek(file.pos()); |
|
1632 |
QCOMPARE(file.pos(), qint64(1)); |
|
1633 |
||
1634 |
} |
|
1635 |
||
1636 |
||
1637 |
void tst_QFile::FILEReadWrite() |
|
1638 |
{ |
|
1639 |
// Tests modifing a file. First creates it then reads in 4 bytes and then overwrites these |
|
1640 |
// 4 bytes with new values. At the end check to see the file contains the new values. |
|
1641 |
||
1642 |
QFile::remove("FILEReadWrite.txt"); |
|
1643 |
||
1644 |
// create test file |
|
1645 |
{ |
|
1646 |
QFile f("FILEReadWrite.txt"); |
|
1647 |
QVERIFY(f.open(QFile::WriteOnly)); |
|
1648 |
QDataStream ds(&f); |
|
1649 |
qint8 c = 0; |
|
1650 |
ds << c; |
|
1651 |
c = 1; |
|
1652 |
ds << c; |
|
1653 |
c = 2; |
|
1654 |
ds << c; |
|
1655 |
c = 3; |
|
1656 |
ds << c; |
|
1657 |
c = 4; |
|
1658 |
ds << c; |
|
1659 |
c = 5; |
|
1660 |
ds << c; |
|
1661 |
c = 6; |
|
1662 |
ds << c; |
|
1663 |
c = 7; |
|
1664 |
ds << c; |
|
1665 |
c = 8; |
|
1666 |
ds << c; |
|
1667 |
c = 9; |
|
1668 |
ds << c; |
|
1669 |
c = 10; |
|
1670 |
ds << c; |
|
1671 |
c = 11; |
|
1672 |
ds << c; |
|
1673 |
f.close(); |
|
1674 |
} |
|
1675 |
||
1676 |
#ifdef Q_OS_WINCE |
|
1677 |
FILE *fp = fopen(qPrintable(QCoreApplication::applicationDirPath() + "\\FILEReadWrite.txt"), "r+b"); |
|
1678 |
#else |
|
1679 |
FILE *fp = fopen("FILEReadWrite.txt", "r+b"); |
|
1680 |
#endif |
|
1681 |
QVERIFY(fp); |
|
1682 |
QFile file; |
|
1683 |
QVERIFY(file.open(fp, QFile::ReadWrite)); |
|
1684 |
QDataStream sfile(&file) ; |
|
1685 |
||
1686 |
qint8 var1,var2,var3,var4; |
|
1687 |
while (!sfile.atEnd()) |
|
1688 |
{ |
|
1689 |
qint64 base = file.pos(); |
|
1690 |
||
1691 |
QCOMPARE(file.pos(), base + 0); |
|
1692 |
sfile >> var1; |
|
1693 |
QCOMPARE(file.pos(), base + 1); |
|
1694 |
file.flush(); // flushing should not change the base |
|
1695 |
QCOMPARE(file.pos(), base + 1); |
|
1696 |
sfile >> var2; |
|
1697 |
QCOMPARE(file.pos(), base + 2); |
|
1698 |
sfile >> var3; |
|
1699 |
QCOMPARE(file.pos(), base + 3); |
|
1700 |
sfile >> var4; |
|
1701 |
QCOMPARE(file.pos(), base + 4); |
|
1702 |
file.seek(file.pos() - 4) ; // Move it back 4, for we are going to write new values based on old ones |
|
1703 |
QCOMPARE(file.pos(), base + 0); |
|
1704 |
sfile << qint8(var1 + 5); |
|
1705 |
QCOMPARE(file.pos(), base + 1); |
|
1706 |
sfile << qint8(var2 + 5); |
|
1707 |
QCOMPARE(file.pos(), base + 2); |
|
1708 |
sfile << qint8(var3 + 5); |
|
1709 |
QCOMPARE(file.pos(), base + 3); |
|
1710 |
sfile << qint8(var4 + 5); |
|
1711 |
QCOMPARE(file.pos(), base + 4); |
|
1712 |
||
1713 |
} |
|
1714 |
file.close(); |
|
1715 |
fclose(fp); |
|
1716 |
||
1717 |
// check modified file |
|
1718 |
{ |
|
1719 |
QFile f("FILEReadWrite.txt"); |
|
1720 |
QVERIFY(f.open(QFile::ReadOnly)); |
|
1721 |
QDataStream ds(&f); |
|
1722 |
qint8 c = 0; |
|
1723 |
ds >> c; |
|
1724 |
QCOMPARE(c, (qint8)5); |
|
1725 |
ds >> c; |
|
1726 |
QCOMPARE(c, (qint8)6); |
|
1727 |
ds >> c; |
|
1728 |
QCOMPARE(c, (qint8)7); |
|
1729 |
ds >> c; |
|
1730 |
QCOMPARE(c, (qint8)8); |
|
1731 |
ds >> c; |
|
1732 |
QCOMPARE(c, (qint8)9); |
|
1733 |
ds >> c; |
|
1734 |
QCOMPARE(c, (qint8)10); |
|
1735 |
ds >> c; |
|
1736 |
QCOMPARE(c, (qint8)11); |
|
1737 |
ds >> c; |
|
1738 |
QCOMPARE(c, (qint8)12); |
|
1739 |
ds >> c; |
|
1740 |
QCOMPARE(c, (qint8)13); |
|
1741 |
ds >> c; |
|
1742 |
QCOMPARE(c, (qint8)14); |
|
1743 |
ds >> c; |
|
1744 |
QCOMPARE(c, (qint8)15); |
|
1745 |
ds >> c; |
|
1746 |
QCOMPARE(c, (qint8)16); |
|
1747 |
f.close(); |
|
1748 |
} |
|
1749 |
||
1750 |
QFile::remove("FILEReadWrite.txt"); |
|
1751 |
} |
|
1752 |
||
1753 |
||
1754 |
/* |
|
1755 |
#include <qglobal.h> |
|
1756 |
#define BUFFSIZE 1 |
|
1757 |
#define FILESIZE 0x10000000f |
|
1758 |
void tst_QFile::largeFileSupport() |
|
1759 |
{ |
|
1760 |
#ifdef Q_OS_SOLARIS |
|
1761 |
QSKIP("Solaris does not support statfs", SkipAll); |
|
1762 |
#else |
|
1763 |
qlonglong sizeNeeded = 2147483647; |
|
1764 |
sizeNeeded *= 2; |
|
1765 |
sizeNeeded += 1024; |
|
1766 |
qlonglong freespace = qlonglong(0); |
|
1767 |
#ifdef Q_WS_WIN |
|
1768 |
_ULARGE_INTEGER free; |
|
1769 |
if (::GetDiskFreeSpaceEx((wchar_t*)QDir::currentPath().utf16(), &free, 0, 0)) |
|
1770 |
freespace = free.QuadPart; |
|
1771 |
if (freespace != 0) { |
|
1772 |
#elif defined(Q_OS_IRIX) |
|
1773 |
struct statfs info; |
|
1774 |
if (statfs(QDir::currentPath().local8Bit(), &info, sizeof(struct statfs), 0) == 0) { |
|
1775 |
freespace = qlonglong(info.f_bfree * info.f_bsize); |
|
1776 |
#else |
|
1777 |
struct statfs info; |
|
1778 |
if (statfs(const_cast<char *>(QDir::currentPath().toLocal8Bit().constData()), &info) == 0) { |
|
1779 |
freespace = qlonglong(info.f_bavail * info.f_bsize); |
|
1780 |
#endif |
|
1781 |
if (freespace > sizeNeeded) { |
|
1782 |
QFile bigFile("bigfile"); |
|
1783 |
if (bigFile.open(QFile::ReadWrite)) { |
|
1784 |
char c[BUFFSIZE] = {'a'}; |
|
1785 |
QVERIFY(bigFile.write(c, BUFFSIZE) == BUFFSIZE); |
|
1786 |
qlonglong oldPos = bigFile.pos(); |
|
1787 |
QVERIFY(bigFile.resize(sizeNeeded)); |
|
1788 |
QCOMPARE(oldPos, bigFile.pos()); |
|
1789 |
QVERIFY(bigFile.seek(sizeNeeded - BUFFSIZE)); |
|
1790 |
QVERIFY(bigFile.write(c, BUFFSIZE) == BUFFSIZE); |
|
1791 |
||
1792 |
bigFile.close(); |
|
1793 |
if (bigFile.open(QFile::ReadOnly)) { |
|
1794 |
QVERIFY(bigFile.read(c, BUFFSIZE) == BUFFSIZE); |
|
1795 |
int i = 0; |
|
1796 |
for (i=0; i<BUFFSIZE; i++) |
|
1797 |
QCOMPARE(c[i], 'a'); |
|
1798 |
QVERIFY(bigFile.seek(sizeNeeded - BUFFSIZE)); |
|
1799 |
QVERIFY(bigFile.read(c, BUFFSIZE) == BUFFSIZE); |
|
1800 |
for (i=0; i<BUFFSIZE; i++) |
|
1801 |
QCOMPARE(c[i], 'a'); |
|
1802 |
bigFile.close(); |
|
1803 |
QVERIFY(bigFile.remove()); |
|
1804 |
} else { |
|
1805 |
QVERIFY(bigFile.remove()); |
|
1806 |
QFAIL("Could not reopen file"); |
|
1807 |
} |
|
1808 |
} else { |
|
1809 |
QFAIL("Could not open file"); |
|
1810 |
} |
|
1811 |
} else { |
|
1812 |
QSKIP("Not enough space to run test", SkipSingle); |
|
1813 |
} |
|
1814 |
} else { |
|
1815 |
QFAIL("Could not determin disk space"); |
|
1816 |
} |
|
1817 |
#endif |
|
1818 |
} |
|
1819 |
*/ |
|
1820 |
||
1821 |
void tst_QFile::i18nFileName_data() |
|
1822 |
{ |
|
1823 |
QTest::addColumn<QString>("fileName"); |
|
1824 |
||
1825 |
QTest::newRow( "01" ) << QString::fromUtf8("xxxxxxx.txt"); |
|
1826 |
} |
|
1827 |
||
1828 |
void tst_QFile::i18nFileName() |
|
1829 |
{ |
|
1830 |
QFETCH(QString, fileName); |
|
1831 |
if (QFile::exists(fileName)) { |
|
1832 |
QVERIFY(QFile::remove(fileName)); |
|
1833 |
} |
|
1834 |
{ |
|
1835 |
QFile file(fileName); |
|
1836 |
QVERIFY(file.open(QFile::WriteOnly | QFile::Text)); |
|
1837 |
QTextStream ts(&file); |
|
1838 |
ts.setCodec("UTF-8"); |
|
1839 |
ts << fileName << endl; |
|
1840 |
} |
|
1841 |
{ |
|
1842 |
QFile file(fileName); |
|
1843 |
QVERIFY(file.open(QFile::ReadOnly | QFile::Text)); |
|
1844 |
QTextStream ts(&file); |
|
1845 |
ts.setCodec("UTF-8"); |
|
1846 |
QString line = ts.readLine(); |
|
1847 |
QCOMPARE(line, fileName); |
|
1848 |
} |
|
1849 |
QVERIFY(QFile::remove(fileName)); |
|
1850 |
} |
|
1851 |
||
1852 |
||
1853 |
void tst_QFile::longFileName_data() |
|
1854 |
{ |
|
1855 |
QTest::addColumn<QString>("fileName"); |
|
1856 |
||
1857 |
QTest::newRow( "16 chars" ) << QString::fromLatin1("longFileName.txt"); |
|
1858 |
QTest::newRow( "52 chars" ) << QString::fromLatin1("longFileNamelongFileNamelongFileNamelongFileName.txt"); |
|
1859 |
QTest::newRow( "148 chars" ) << QString::fromLatin1("longFileNamelongFileNamelongFileNamelongFileName" |
|
1860 |
"longFileNamelongFileNamelongFileNamelongFileName" |
|
1861 |
"longFileNamelongFileNamelongFileNamelongFileName.txt"); |
|
1862 |
QTest::newRow( "244 chars" ) << QString::fromLatin1("longFileNamelongFileNamelongFileNamelongFileName" |
|
1863 |
"longFileNamelongFileNamelongFileNamelongFileName" |
|
1864 |
"longFileNamelongFileNamelongFileNamelongFileName" |
|
1865 |
"longFileNamelongFileNamelongFileNamelongFileName" |
|
1866 |
"longFileNamelongFileNamelongFileNamelongFileName.txt"); |
|
1867 |
QTest::newRow( "244 chars to absolutepath" ) << QFileInfo(QString::fromLatin1("longFileNamelongFileNamelongFileNamelongFileName" |
|
1868 |
"longFileNamelongFileNamelongFileNamelongFileName" |
|
1869 |
"longFileNamelongFileNamelongFileNamelongFileName" |
|
1870 |
"longFileNamelongFileNamelongFileNamelongFileName" |
|
1871 |
"longFileNamelongFileNamelongFileNamelongFileName.txt")).absoluteFilePath(); |
|
1872 |
/* needs to be put on a windows 2000 > test machine |
|
1873 |
QTest::newRow( "244 chars on UNC" ) << QString::fromLatin1("//arsia/D/troll/tmp/longFileNamelongFileNamelongFileNamelongFileName" |
|
1874 |
"longFileNamelongFileNamelongFileNamelongFileName" |
|
1875 |
"longFileNamelongFileNamelongFileNamelongFileName" |
|
1876 |
"longFileNamelongFileNamelongFileNamelongFileName" |
|
1877 |
"longFileNamelongFileNamelongFileNamelongFileName.txt");*/ |
|
1878 |
} |
|
1879 |
||
1880 |
void tst_QFile::longFileName() |
|
1881 |
{ |
|
1882 |
QFETCH(QString, fileName); |
|
1883 |
if (QFile::exists(fileName)) { |
|
1884 |
QVERIFY(QFile::remove(fileName)); |
|
1885 |
} |
|
1886 |
{ |
|
1887 |
QFile file(fileName); |
|
1888 |
#if defined(Q_OS_WINCE) || defined(Q_OS_SYMBIAN) |
|
1889 |
QEXPECT_FAIL("244 chars", "Full pathname must be less than 260 chars", Abort); |
|
1890 |
QEXPECT_FAIL("244 chars to absolutepath", "Full pathname must be less than 260 chars", Abort); |
|
1891 |
#endif |
|
1892 |
QVERIFY(file.open(QFile::WriteOnly | QFile::Text)); |
|
1893 |
QTextStream ts(&file); |
|
1894 |
ts << fileName << endl; |
|
1895 |
} |
|
1896 |
{ |
|
1897 |
QFile file(fileName); |
|
1898 |
QVERIFY(file.open(QFile::ReadOnly | QFile::Text)); |
|
1899 |
QTextStream ts(&file); |
|
1900 |
QString line = ts.readLine(); |
|
1901 |
QCOMPARE(line, fileName); |
|
1902 |
} |
|
1903 |
QString newName = fileName + QLatin1String("1"); |
|
1904 |
{ |
|
1905 |
QVERIFY(QFile::copy(fileName, newName)); |
|
1906 |
QFile file(newName); |
|
1907 |
QVERIFY(file.open(QFile::ReadOnly | QFile::Text)); |
|
1908 |
QTextStream ts(&file); |
|
1909 |
QString line = ts.readLine(); |
|
1910 |
QCOMPARE(line, fileName); |
|
1911 |
||
1912 |
} |
|
1913 |
QVERIFY(QFile::remove(newName)); |
|
1914 |
{ |
|
1915 |
QVERIFY(QFile::rename(fileName, newName)); |
|
1916 |
QFile file(newName); |
|
1917 |
QVERIFY(file.open(QFile::ReadOnly | QFile::Text)); |
|
1918 |
QTextStream ts(&file); |
|
1919 |
QString line = ts.readLine(); |
|
1920 |
QCOMPARE(line, fileName); |
|
1921 |
} |
|
1922 |
QVERIFY(QFile::exists(newName)); |
|
1923 |
QVERIFY(QFile::remove(newName)); |
|
1924 |
} |
|
1925 |
||
1926 |
class MyEngine : public QAbstractFileEngine |
|
1927 |
{ |
|
1928 |
public: |
|
1929 |
MyEngine(int n) { number = n; } |
|
1930 |
virtual ~MyEngine() {} |
|
1931 |
||
1932 |
void setFileName(const QString &) {} |
|
1933 |
bool open(int ) { return false; } |
|
1934 |
bool close() { return false; } |
|
1935 |
bool flush() { return false; } |
|
1936 |
qint64 size() const { return 123 + number; } |
|
1937 |
qint64 at() const { return -1; } |
|
1938 |
bool seek(qint64) { return false; } |
|
1939 |
bool isSequential() const { return false; } |
|
1940 |
qint64 read(char *, qint64) { return -1; } |
|
1941 |
qint64 write(const char *, qint64) { return -1; } |
|
1942 |
bool remove() { return false; } |
|
1943 |
bool copy(const QString &) { return false; } |
|
1944 |
bool rename(const QString &) { return false; } |
|
1945 |
bool link(const QString &) { return false; } |
|
1946 |
bool mkdir(const QString &, bool) const { return false; } |
|
1947 |
bool rmdir(const QString &, bool) const { return false; } |
|
1948 |
bool setSize(qint64) { return false; } |
|
1949 |
QStringList entryList(QDir::Filters, const QStringList &) const { return QStringList(); } |
|
1950 |
bool caseSensitive() const { return false; } |
|
1951 |
bool isRelativePath() const { return false; } |
|
1952 |
FileFlags fileFlags(FileFlags) const { return 0; } |
|
1953 |
bool chmod(uint) { return false; } |
|
1954 |
QString fileName(FileName) const { return name; } |
|
1955 |
uint ownerId(FileOwner) const { return 0; } |
|
1956 |
QString owner(FileOwner) const { return QString(); } |
|
1957 |
QDateTime fileTime(FileTime) const { return QDateTime(); } |
|
1958 |
||
1959 |
private: |
|
1960 |
int number; |
|
1961 |
QString name; |
|
1962 |
}; |
|
1963 |
||
1964 |
class MyHandler : public QAbstractFileEngineHandler |
|
1965 |
{ |
|
1966 |
public: |
|
1967 |
inline QAbstractFileEngine *create(const QString &) const |
|
1968 |
{ |
|
1969 |
return new MyEngine(1); |
|
1970 |
} |
|
1971 |
}; |
|
1972 |
||
1973 |
class MyHandler2 : public QAbstractFileEngineHandler |
|
1974 |
{ |
|
1975 |
public: |
|
1976 |
inline QAbstractFileEngine *create(const QString &) const |
|
1977 |
{ |
|
1978 |
return new MyEngine(2); |
|
1979 |
} |
|
1980 |
}; |
|
1981 |
||
1982 |
void tst_QFile::fileEngineHandler() |
|
1983 |
{ |
|
1984 |
// A file that does not exist has a size of 0. |
|
1985 |
QFile::remove("ole.bull"); |
|
1986 |
QFile file("ole.bull"); |
|
1987 |
QCOMPARE(file.size(), qint64(0)); |
|
1988 |
||
1989 |
// Instantiating our handler will enable the new engine. |
|
1990 |
MyHandler handler; |
|
1991 |
file.setFileName("ole.bull"); |
|
1992 |
QCOMPARE(file.size(), qint64(124)); |
|
1993 |
||
1994 |
// A new, identical handler should take preference over the last one. |
|
1995 |
MyHandler2 handler2; |
|
1996 |
file.setFileName("ole.bull"); |
|
1997 |
QCOMPARE(file.size(), qint64(125)); |
|
1998 |
||
1999 |
} |
|
2000 |
||
2001 |
class MyRecursiveHandler : public QAbstractFileEngineHandler |
|
2002 |
{ |
|
2003 |
public: |
|
2004 |
inline QAbstractFileEngine *create(const QString &fileName) const |
|
2005 |
{ |
|
2006 |
if (fileName.startsWith(":!")) { |
|
2007 |
QDir dir; |
|
2008 |
QString realFile = SRCDIR + fileName.mid(2); |
|
2009 |
if (dir.exists(realFile)) |
|
2010 |
return new QFSFileEngine(realFile); |
|
2011 |
} |
|
2012 |
return 0; |
|
2013 |
} |
|
2014 |
}; |
|
2015 |
||
2016 |
void tst_QFile::useQFileInAFileHandler() |
|
2017 |
{ |
|
2018 |
// This test should not dead-lock |
|
2019 |
MyRecursiveHandler handler; |
|
2020 |
QFile file(":!tst_qfile.cpp"); |
|
2021 |
QVERIFY(file.exists()); |
|
2022 |
} |
|
2023 |
||
2024 |
void tst_QFile::getCharFF() |
|
2025 |
{ |
|
2026 |
QFile file("file.txt"); |
|
2027 |
file.open(QFile::ReadWrite); |
|
2028 |
file.write("\xff\xff\xff"); |
|
2029 |
file.flush(); |
|
2030 |
file.seek(0); |
|
2031 |
||
2032 |
char c; |
|
2033 |
QVERIFY(file.getChar(&c)); |
|
2034 |
QVERIFY(file.getChar(&c)); |
|
2035 |
QVERIFY(file.getChar(&c)); |
|
2036 |
} |
|
2037 |
||
2038 |
void tst_QFile::remove_and_exists() |
|
2039 |
{ |
|
2040 |
QFile::remove("tull_i_grunn.txt"); |
|
2041 |
QFile f("tull_i_grunn.txt"); |
|
2042 |
||
2043 |
QVERIFY(!f.exists()); |
|
2044 |
||
2045 |
bool opened = f.open(QIODevice::WriteOnly); |
|
2046 |
QVERIFY(opened); |
|
2047 |
||
2048 |
f.write(QString("testing that remove/exists work...").toLatin1()); |
|
2049 |
f.close(); |
|
2050 |
||
2051 |
QVERIFY(f.exists()); |
|
2052 |
||
2053 |
f.remove(); |
|
2054 |
QVERIFY(!f.exists()); |
|
2055 |
} |
|
2056 |
||
2057 |
void tst_QFile::removeOpenFile() |
|
2058 |
{ |
|
2059 |
{ |
|
2060 |
// remove an opened, write-only file |
|
2061 |
QFile::remove("remove_unclosed.txt"); |
|
2062 |
QFile f("remove_unclosed.txt"); |
|
2063 |
||
2064 |
QVERIFY(!f.exists()); |
|
2065 |
bool opened = f.open(QIODevice::WriteOnly); |
|
2066 |
QVERIFY(opened); |
|
2067 |
f.write(QString("testing that remove closes the file first...").toLatin1()); |
|
2068 |
||
2069 |
bool removed = f.remove(); // remove should both close and remove the file |
|
2070 |
QVERIFY(removed); |
|
2071 |
QVERIFY(!f.isOpen()); |
|
2072 |
QVERIFY(!f.exists()); |
|
2073 |
QVERIFY(f.error() == QFile::NoError); |
|
2074 |
} |
|
2075 |
||
2076 |
{ |
|
2077 |
// remove an opened, read-only file |
|
2078 |
QFile::remove("remove_unclosed.txt"); |
|
2079 |
||
2080 |
// first, write a file that we can remove |
|
2081 |
{ |
|
2082 |
QFile f("remove_unclosed.txt"); |
|
2083 |
QVERIFY(!f.exists()); |
|
2084 |
bool opened = f.open(QIODevice::WriteOnly); |
|
2085 |
QVERIFY(opened); |
|
2086 |
f.write(QString("testing that remove closes the file first...").toLatin1()); |
|
2087 |
f.close(); |
|
2088 |
} |
|
2089 |
||
2090 |
QFile f("remove_unclosed.txt"); |
|
2091 |
bool opened = f.open(QIODevice::ReadOnly); |
|
2092 |
QVERIFY(opened); |
|
2093 |
f.readAll(); |
|
2094 |
// this used to only fail on FreeBSD (and Mac OS X) |
|
2095 |
QVERIFY(f.flush()); |
|
2096 |
bool removed = f.remove(); // remove should both close and remove the file |
|
2097 |
QVERIFY(removed); |
|
2098 |
QVERIFY(!f.isOpen()); |
|
2099 |
QVERIFY(!f.exists()); |
|
2100 |
QVERIFY(f.error() == QFile::NoError); |
|
2101 |
} |
|
2102 |
} |
|
2103 |
||
2104 |
void tst_QFile::fullDisk() |
|
2105 |
{ |
|
2106 |
QFile file("/dev/full"); |
|
2107 |
if (!file.exists()) |
|
2108 |
QSKIP("/dev/full doesn't exist on this system", SkipAll); |
|
2109 |
||
2110 |
QVERIFY(file.open(QIODevice::WriteOnly)); |
|
2111 |
file.write("foobar", 6); |
|
2112 |
||
2113 |
QVERIFY(!file.flush()); |
|
2114 |
QCOMPARE(file.error(), QFile::ResourceError); |
|
2115 |
QVERIFY(!file.flush()); |
|
2116 |
QCOMPARE(file.error(), QFile::ResourceError); |
|
2117 |
||
2118 |
char c = 0; |
|
2119 |
file.write(&c, 0); |
|
2120 |
QVERIFY(!file.flush()); |
|
2121 |
QCOMPARE(file.error(), QFile::ResourceError); |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2122 |
QCOMPARE(file.write(&c, 1), qint64(1)); |
0 | 2123 |
QVERIFY(!file.flush()); |
2124 |
QCOMPARE(file.error(), QFile::ResourceError); |
|
2125 |
||
2126 |
file.close(); |
|
2127 |
QVERIFY(!file.isOpen()); |
|
2128 |
QCOMPARE(file.error(), QFile::ResourceError); |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2129 |
|
0 | 2130 |
file.open(QIODevice::WriteOnly); |
2131 |
QCOMPARE(file.error(), QFile::NoError); |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2132 |
QVERIFY(file.flush()); // Shouldn't inherit write buffer |
0 | 2133 |
file.close(); |
2134 |
QCOMPARE(file.error(), QFile::NoError); |
|
2135 |
||
2136 |
// try again without flush: |
|
2137 |
QVERIFY(file.open(QIODevice::WriteOnly)); |
|
2138 |
file.write("foobar", 6); |
|
2139 |
file.close(); |
|
2140 |
QVERIFY(file.error() != QFile::NoError); |
|
2141 |
} |
|
2142 |
||
2143 |
void tst_QFile::writeLargeDataBlock_data() |
|
2144 |
{ |
|
2145 |
QTest::addColumn<QString>("fileName"); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2146 |
QTest::addColumn<int>("type"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2147 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2148 |
QTest::newRow("localfile-QFile") << "./largeblockfile.txt" << (int)OpenQFile; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2149 |
QTest::newRow("localfile-Fd") << "./largeblockfile.txt" << (int)OpenFd; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2150 |
QTest::newRow("localfile-Stream") << "./largeblockfile.txt" << (int)OpenStream; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2151 |
|
0 | 2152 |
#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) |
2153 |
// Some semi-randomness to avoid collisions. |
|
2154 |
QTest::newRow("unc file") |
|
2155 |
<< QString("//" + QtNetworkSettings::winServerName() + "/TESTSHAREWRITABLE/largefile-%1-%2.txt") |
|
2156 |
.arg(QHostInfo::localHostName()) |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2157 |
.arg(QTime::currentTime().msec()) << (int)OpenQFile; |
0 | 2158 |
#endif |
2159 |
} |
|
2160 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2161 |
static QByteArray getLargeDataBlock() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2162 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2163 |
static QByteArray array; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2164 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2165 |
if (array.isNull()) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2166 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2167 |
#if defined(Q_OS_WINCE) || defined(Q_OS_SYMBIAN) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2168 |
int resizeSize = 1024 * 1024; // WinCE and Symbian do not have much space |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2169 |
#else |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2170 |
int resizeSize = 64 * 1024 * 1024; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2171 |
#endif |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2172 |
array.resize(resizeSize); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2173 |
for (int i = 0; i < array.size(); ++i) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2174 |
array[i] = uchar(i); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2175 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2176 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2177 |
return array; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2178 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2179 |
|
0 | 2180 |
void tst_QFile::writeLargeDataBlock() |
2181 |
{ |
|
2182 |
QFETCH(QString, fileName); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2183 |
QFETCH( int, type ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2184 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2185 |
QByteArray const originalData = getLargeDataBlock(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2186 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2187 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2188 |
QFile file(fileName); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2189 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2190 |
QVERIFY2( openFile(file, QIODevice::WriteOnly, (FileType)type), |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2191 |
qPrintable(QString("Couldn't open file for writing: [%1]").arg(fileName)) ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2192 |
QCOMPARE( file.write(originalData), (qint64)originalData.size() ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2193 |
QVERIFY( file.flush() ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2194 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2195 |
closeFile(file); |
0 | 2196 |
} |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2197 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2198 |
QByteArray readData; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2199 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2200 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2201 |
QFile file(fileName); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2202 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2203 |
QVERIFY2( openFile(file, QIODevice::ReadOnly, (FileType)type), |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2204 |
qPrintable(QString("Couldn't open file for reading: [%1]").arg(fileName)) ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2205 |
readData = file.readAll(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2206 |
closeFile(file); |
0 | 2207 |
} |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2208 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2209 |
QCOMPARE( readData, originalData ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2210 |
QVERIFY( QFile::remove(fileName) ); |
0 | 2211 |
} |
2212 |
||
2213 |
void tst_QFile::readFromWriteOnlyFile() |
|
2214 |
{ |
|
2215 |
QFile file("writeonlyfile"); |
|
2216 |
QVERIFY(file.open(QFile::WriteOnly)); |
|
2217 |
char c; |
|
2218 |
QTest::ignoreMessage(QtWarningMsg, "QIODevice::read: WriteOnly device"); |
|
2219 |
QCOMPARE(file.read(&c, 1), qint64(-1)); |
|
2220 |
} |
|
2221 |
||
2222 |
void tst_QFile::writeToReadOnlyFile() |
|
2223 |
{ |
|
2224 |
QFile file("readonlyfile"); |
|
2225 |
QVERIFY(file.open(QFile::ReadOnly)); |
|
2226 |
char c = 0; |
|
2227 |
QTest::ignoreMessage(QtWarningMsg, "QIODevice::write: ReadOnly device"); |
|
2228 |
QCOMPARE(file.write(&c, 1), qint64(-1)); |
|
2229 |
} |
|
2230 |
||
2231 |
void tst_QFile::virtualFile() |
|
2232 |
{ |
|
2233 |
// test if QFile works with virtual files |
|
2234 |
QString fname; |
|
2235 |
#if defined(Q_OS_LINUX) |
|
2236 |
fname = "/proc/self/maps"; |
|
2237 |
#elif defined(Q_OS_AIX) |
|
2238 |
fname = QString("/proc/%1/map").arg(getpid()); |
|
2239 |
#elif defined(Q_OS_FREEBSD) || defined(Q_OS_NETBSD) |
|
2240 |
fname = "/proc/curproc/map"; |
|
2241 |
#else |
|
2242 |
QSKIP("This platform does not have 0-sized virtual files", SkipAll); |
|
2243 |
#endif |
|
2244 |
||
2245 |
// consistency check |
|
2246 |
QFileInfo fi(fname); |
|
2247 |
QVERIFY(fi.exists()); |
|
2248 |
QVERIFY(fi.isFile()); |
|
2249 |
QCOMPARE(fi.size(), Q_INT64_C(0)); |
|
2250 |
||
2251 |
// open the file |
|
2252 |
QFile f(fname); |
|
2253 |
QVERIFY(f.open(QIODevice::ReadOnly)); |
|
2254 |
QCOMPARE(f.size(), Q_INT64_C(0)); |
|
2255 |
QVERIFY(f.atEnd()); |
|
2256 |
||
2257 |
// read data |
|
2258 |
QByteArray data = f.read(16); |
|
2259 |
QCOMPARE(data.size(), 16); |
|
2260 |
QCOMPARE(f.pos(), Q_INT64_C(16)); |
|
2261 |
||
2262 |
// line-reading |
|
2263 |
data = f.readLine(); |
|
2264 |
QVERIFY(!data.isEmpty()); |
|
2265 |
||
2266 |
// read all: |
|
2267 |
data = f.readAll(); |
|
2268 |
QVERIFY(f.pos() != 0); |
|
2269 |
QVERIFY(!data.isEmpty()); |
|
2270 |
||
2271 |
// seeking |
|
2272 |
QVERIFY(f.seek(1)); |
|
2273 |
QCOMPARE(f.pos(), Q_INT64_C(1)); |
|
2274 |
} |
|
2275 |
||
2276 |
void tst_QFile::textFile() |
|
2277 |
{ |
|
2278 |
#if defined(Q_OS_WINCE) |
|
2279 |
FILE *fs = ::fopen((QCoreApplication::applicationDirPath() + "/writeabletextfile").toAscii() , "wt"); |
|
2280 |
#elif defined(Q_OS_WIN) |
|
2281 |
FILE *fs = ::fopen("writeabletextfile", "wt"); |
|
2282 |
#else |
|
2283 |
FILE *fs = ::fopen("writeabletextfile", "w"); |
|
2284 |
#endif |
|
2285 |
QFile f; |
|
2286 |
QByteArray part1("This\nis\na\nfile\nwith\nnewlines\n"); |
|
2287 |
QByteArray part2("Add\nsome\nmore\nnewlines\n"); |
|
2288 |
||
2289 |
QVERIFY(f.open(fs, QIODevice::WriteOnly)); |
|
2290 |
f.write(part1); |
|
2291 |
f.write(part2); |
|
2292 |
f.close(); |
|
2293 |
::fclose(fs); |
|
2294 |
||
2295 |
QFile file("writeabletextfile"); |
|
2296 |
QVERIFY(file.open(QIODevice::ReadOnly)); |
|
2297 |
||
2298 |
QByteArray data = file.readAll(); |
|
2299 |
||
2300 |
QByteArray expected = part1 + part2; |
|
2301 |
#ifdef Q_OS_WIN |
|
2302 |
expected.replace("\n", "\015\012"); |
|
2303 |
#endif |
|
2304 |
QCOMPARE(data, expected); |
|
2305 |
file.close(); |
|
2306 |
file.remove(); |
|
2307 |
} |
|
2308 |
||
2309 |
void tst_QFile::rename_data() |
|
2310 |
{ |
|
2311 |
QTest::addColumn<QString>("source"); |
|
2312 |
QTest::addColumn<QString>("destination"); |
|
2313 |
QTest::addColumn<bool>("result"); |
|
2314 |
||
2315 |
QTest::newRow("a -> b") << QString("a") << QString("b") << false; |
|
2316 |
QTest::newRow("a -> .") << QString("a") << QString(".") << false; |
|
2317 |
QTest::newRow("renamefile -> renamefile") << QString("renamefile") << QString("renamefile") << false; |
|
2318 |
QTest::newRow("renamefile -> Makefile") << QString("renamefile") << QString("Makefile") << false; |
|
2319 |
#if defined(Q_OS_UNIX) && !defined(Q_OS_SYMBIAN) |
|
2320 |
QTest::newRow("renamefile -> /etc/renamefile") << QString("renamefile") << QString("/etc/renamefile") << false; |
|
2321 |
#endif |
|
2322 |
QTest::newRow("renamefile -> renamedfile") << QString("renamefile") << QString("renamedfile") << true; |
|
2323 |
QTest::newRow("renamefile -> ..") << QString("renamefile") << QString("..") << false; |
|
2324 |
} |
|
2325 |
||
2326 |
void tst_QFile::rename() |
|
2327 |
{ |
|
2328 |
QFETCH(QString, source); |
|
2329 |
QFETCH(QString, destination); |
|
2330 |
QFETCH(bool, result); |
|
2331 |
||
2332 |
QFile::remove("renamedfile"); |
|
2333 |
QFile f("renamefile"); |
|
2334 |
f.open(QFile::WriteOnly); |
|
2335 |
f.close(); |
|
2336 |
||
2337 |
QFile file(source); |
|
2338 |
QCOMPARE(file.rename(destination), result); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2339 |
|
0 | 2340 |
if (result) |
2341 |
QCOMPARE(file.error(), QFile::NoError); |
|
2342 |
else |
|
2343 |
QCOMPARE(file.error(), QFile::RenameError); |
|
2344 |
||
2345 |
QFile::remove("renamefile"); |
|
2346 |
} |
|
2347 |
||
2348 |
/*! |
|
2349 |
\since 4.5 |
|
2350 |
||
2351 |
Some special files have QFile::atEnd() returning true, even though there is |
|
2352 |
more data available. True for corner cases, as well as some mounts on OS X. |
|
2353 |
||
2354 |
Here, we reproduce that condition by having a QFile sub-class with this |
|
2355 |
peculiar atEnd() behavior. |
|
2356 |
||
2357 |
See task 231583. |
|
2358 |
*/ |
|
2359 |
void tst_QFile::renameWithAtEndSpecialFile() const |
|
2360 |
{ |
|
2361 |
class PeculiarAtEnd : public QFile |
|
2362 |
{ |
|
2363 |
public: |
|
2364 |
virtual bool atEnd() const |
|
2365 |
{ |
|
2366 |
return true; |
|
2367 |
} |
|
2368 |
}; |
|
2369 |
||
2370 |
const QString newName(QLatin1String("newName.txt")); |
|
2371 |
/* Cleanup, so we're a bit more robust. */ |
|
2372 |
QFile::remove(newName); |
|
2373 |
||
2374 |
const QString originalName(QString(SRCDIR "forRenaming.txt")); |
|
2375 |
||
2376 |
PeculiarAtEnd file; |
|
2377 |
file.setFileName(originalName); |
|
2378 |
QVERIFY(file.open(QIODevice::ReadOnly)); |
|
2379 |
||
2380 |
QVERIFY(file.rename(newName)); |
|
2381 |
||
2382 |
file.close(); |
|
2383 |
/* Guess what, we have to rename it back, otherwise we'll fail on second |
|
2384 |
* invocation. */ |
|
2385 |
QVERIFY(QFile::rename(newName, originalName)); |
|
2386 |
} |
|
2387 |
||
2388 |
void tst_QFile::renameFallback() |
|
2389 |
{ |
|
2390 |
// Using a resource file both to trigger QFile::rename's fallback handling |
|
2391 |
// and as a *read-only* source whose move should fail. |
|
2392 |
QFile file(":/rename-fallback.qrc"); |
|
2393 |
QVERIFY(file.exists() && "(test-precondition)"); |
|
2394 |
QFile::remove("file-rename-destination.txt"); |
|
2395 |
||
2396 |
QVERIFY(!file.rename("file-rename-destination.txt")); |
|
2397 |
QVERIFY(!QFile::exists("file-rename-destination.txt")); |
|
2398 |
QVERIFY(!file.isOpen()); |
|
2399 |
} |
|
2400 |
||
2401 |
void tst_QFile::renameMultiple() |
|
2402 |
{ |
|
2403 |
// create the file if it doesn't exist |
|
2404 |
QFile file("file-to-be-renamed.txt"); |
|
2405 |
QFile file2("existing-file.txt"); |
|
2406 |
QVERIFY(file.open(QIODevice::ReadWrite) && "(test-precondition)"); |
|
2407 |
QVERIFY(file2.open(QIODevice::ReadWrite) && "(test-precondition)"); |
|
2408 |
||
2409 |
// any stale files from previous test failures? |
|
2410 |
QFile::remove("file-renamed-once.txt"); |
|
2411 |
QFile::remove("file-renamed-twice.txt"); |
|
2412 |
||
2413 |
// begin testing |
|
2414 |
QVERIFY(QFile::exists("existing-file.txt")); |
|
2415 |
QVERIFY(!file.rename("existing-file.txt")); |
|
2416 |
QCOMPARE(file.error(), QFile::RenameError); |
|
2417 |
QCOMPARE(file.fileName(), QString("file-to-be-renamed.txt")); |
|
2418 |
||
2419 |
QVERIFY(file.rename("file-renamed-once.txt")); |
|
2420 |
QVERIFY(!file.isOpen()); |
|
2421 |
QCOMPARE(file.fileName(), QString("file-renamed-once.txt")); |
|
2422 |
||
2423 |
QVERIFY(QFile::exists("existing-file.txt")); |
|
2424 |
QVERIFY(!file.rename("existing-file.txt")); |
|
2425 |
QCOMPARE(file.error(), QFile::RenameError); |
|
2426 |
QCOMPARE(file.fileName(), QString("file-renamed-once.txt")); |
|
2427 |
||
2428 |
QVERIFY(file.rename("file-renamed-twice.txt")); |
|
2429 |
QVERIFY(!file.isOpen()); |
|
2430 |
QCOMPARE(file.fileName(), QString("file-renamed-twice.txt")); |
|
2431 |
||
2432 |
QVERIFY(QFile::exists("existing-file.txt")); |
|
2433 |
QVERIFY(!QFile::exists("file-to-be-renamed.txt")); |
|
2434 |
QVERIFY(!QFile::exists("file-renamed-once.txt")); |
|
2435 |
QVERIFY(QFile::exists("file-renamed-twice.txt")); |
|
2436 |
||
2437 |
file.remove(); |
|
2438 |
file2.remove(); |
|
2439 |
QVERIFY(!QFile::exists("file-renamed-twice.txt")); |
|
2440 |
QVERIFY(!QFile::exists("existing-file.txt")); |
|
2441 |
} |
|
2442 |
||
2443 |
void tst_QFile::appendAndRead() |
|
2444 |
{ |
|
2445 |
QFile writeFile(QLatin1String("appendfile.txt")); |
|
2446 |
QVERIFY(writeFile.open(QIODevice::WriteOnly | QIODevice::Truncate)); |
|
2447 |
||
2448 |
QFile readFile(QLatin1String("appendfile.txt")); |
|
2449 |
QVERIFY(readFile.open(QIODevice::ReadOnly)); |
|
2450 |
||
2451 |
// Write to the end of the file, then read that character back, and so on. |
|
2452 |
for (int i = 0; i < 100; ++i) { |
|
2453 |
char c = '\0'; |
|
2454 |
writeFile.putChar(char(i % 256)); |
|
2455 |
writeFile.flush(); |
|
2456 |
QVERIFY(readFile.getChar(&c)); |
|
2457 |
QCOMPARE(c, char(i % 256)); |
|
2458 |
QCOMPARE(readFile.pos(), writeFile.pos()); |
|
2459 |
} |
|
2460 |
||
2461 |
// Write blocks and read them back |
|
2462 |
for (int j = 0; j < 18; ++j) { |
|
2463 |
writeFile.write(QByteArray(1 << j, '@')); |
|
2464 |
writeFile.flush(); |
|
2465 |
QCOMPARE(readFile.read(1 << j).size(), 1 << j); |
|
2466 |
} |
|
2467 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2468 |
readFile.close(); |
0 | 2469 |
QFile::remove(QLatin1String("appendfile.txt")); |
2470 |
} |
|
2471 |
||
2472 |
void tst_QFile::miscWithUncPathAsCurrentDir() |
|
2473 |
{ |
|
2474 |
#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) |
|
2475 |
QString current = QDir::currentPath(); |
|
2476 |
QVERIFY(QDir::setCurrent("//" + QtNetworkSettings::winServerName() + "/testsharewritable")); |
|
2477 |
QFile file("test.pri"); |
|
2478 |
QVERIFY(file.exists()); |
|
2479 |
QCOMPARE(int(file.size()), 34); |
|
2480 |
QVERIFY(file.open(QIODevice::ReadOnly)); |
|
2481 |
QVERIFY(QDir::setCurrent(current)); |
|
2482 |
#endif |
|
2483 |
} |
|
2484 |
||
2485 |
void tst_QFile::standarderror() |
|
2486 |
{ |
|
2487 |
QFile f; |
|
2488 |
bool ok = f.open(stderr, QFile::WriteOnly); |
|
2489 |
QVERIFY(ok); |
|
2490 |
f.close(); |
|
2491 |
} |
|
2492 |
||
2493 |
void tst_QFile::handle() |
|
2494 |
{ |
|
2495 |
#ifndef Q_OS_WINCE |
|
2496 |
QFile file(SRCDIR "tst_qfile.cpp"); |
|
2497 |
QVERIFY(file.open(QIODevice::ReadOnly)); |
|
2498 |
int fd = int(file.handle()); |
|
2499 |
QVERIFY(fd > 2); |
|
2500 |
QCOMPARE(int(file.handle()), fd); |
|
2501 |
char c = '\0'; |
|
2502 |
QT_READ(int(file.handle()), &c, 1); |
|
2503 |
QCOMPARE(c, '/'); |
|
2504 |
||
2505 |
// test if the QFile and the handle remain in sync |
|
2506 |
QVERIFY(file.getChar(&c)); |
|
2507 |
QCOMPARE(c, '*'); |
|
2508 |
||
2509 |
// same, but read from QFile first now |
|
2510 |
file.close(); |
|
2511 |
QVERIFY(file.open(QIODevice::ReadOnly | QIODevice::Unbuffered)); |
|
2512 |
fd = int(file.handle()); |
|
2513 |
QVERIFY(fd > 2); |
|
2514 |
QVERIFY(file.getChar(&c)); |
|
2515 |
QCOMPARE(c, '/'); |
|
2516 |
#ifdef Q_OS_UNIX |
|
2517 |
QCOMPARE(QT_READ(fd, &c, 1), ssize_t(1)); |
|
2518 |
#else |
|
2519 |
QCOMPARE(QT_READ(fd, &c, 1), 1); |
|
2520 |
#endif |
|
2521 |
||
2522 |
QCOMPARE(c, '*'); |
|
2523 |
#endif |
|
2524 |
||
2525 |
QFile file2; |
|
2526 |
FILE *fp = fopen(SRCDIR "tst_qfile.cpp", "r"); |
|
2527 |
file2.open(fp, QIODevice::ReadOnly); |
|
2528 |
QCOMPARE(int(file2.handle()), int(fileno(fp))); |
|
2529 |
QCOMPARE(int(file2.handle()), int(fileno(fp))); |
|
2530 |
fclose(fp); |
|
2531 |
||
2532 |
#ifdef Q_OS_UNIX |
|
2533 |
QFile file3; |
|
2534 |
fd = QT_OPEN(SRCDIR "tst_qfile.cpp", QT_OPEN_RDONLY); |
|
2535 |
file3.open(fd, QIODevice::ReadOnly); |
|
2536 |
QCOMPARE(int(file3.handle()), fd); |
|
2537 |
QT_CLOSE(fd); |
|
2538 |
#endif |
|
2539 |
} |
|
2540 |
||
2541 |
void tst_QFile::readEof_data() |
|
2542 |
{ |
|
2543 |
QTest::addColumn<QString>("filename"); |
|
2544 |
QTest::addColumn<int>("imode"); |
|
2545 |
||
2546 |
QTest::newRow("buffered") << SRCDIR "testfile.txt" << 0; |
|
2547 |
QTest::newRow("unbuffered") << SRCDIR "testfile.txt" << int(QIODevice::Unbuffered); |
|
2548 |
||
2549 |
#if defined(Q_OS_UNIX) && !defined(Q_OS_SYMBIAN) |
|
2550 |
QTest::newRow("sequential,buffered") << "/dev/null" << 0; |
|
2551 |
QTest::newRow("sequential,unbuffered") << "/dev/null" << int(QIODevice::Unbuffered); |
|
2552 |
#endif |
|
2553 |
} |
|
2554 |
||
2555 |
void tst_QFile::readEof() |
|
2556 |
{ |
|
2557 |
QFETCH(QString, filename); |
|
2558 |
QFETCH(int, imode); |
|
2559 |
QIODevice::OpenMode mode = QIODevice::OpenMode(imode); |
|
2560 |
||
2561 |
{ |
|
2562 |
QFile file(filename); |
|
2563 |
QVERIFY(file.open(QIODevice::ReadOnly | mode)); |
|
2564 |
bool isSequential = file.isSequential(); |
|
2565 |
if (!isSequential) { |
|
2566 |
QVERIFY(file.seek(245)); |
|
2567 |
QVERIFY(file.atEnd()); |
|
2568 |
} |
|
2569 |
||
2570 |
char buf[10]; |
|
2571 |
int ret = file.read(buf, sizeof buf); |
|
2572 |
QCOMPARE(ret, 0); |
|
2573 |
QVERIFY(file.error() == QFile::NoError); |
|
2574 |
QVERIFY(file.atEnd()); |
|
2575 |
||
2576 |
// Do it again to ensure that we get the same result |
|
2577 |
ret = file.read(buf, sizeof buf); |
|
2578 |
QCOMPARE(ret, 0); |
|
2579 |
QVERIFY(file.error() == QFile::NoError); |
|
2580 |
QVERIFY(file.atEnd()); |
|
2581 |
} |
|
2582 |
||
2583 |
{ |
|
2584 |
QFile file(filename); |
|
2585 |
QVERIFY(file.open(QIODevice::ReadOnly | mode)); |
|
2586 |
bool isSequential = file.isSequential(); |
|
2587 |
if (!isSequential) { |
|
2588 |
QVERIFY(file.seek(245)); |
|
2589 |
QVERIFY(file.atEnd()); |
|
2590 |
} |
|
2591 |
||
2592 |
QByteArray ret = file.read(10); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2593 |
QVERIFY(ret.isEmpty()); |
0 | 2594 |
QVERIFY(file.error() == QFile::NoError); |
2595 |
QVERIFY(file.atEnd()); |
|
2596 |
||
2597 |
// Do it again to ensure that we get the same result |
|
2598 |
ret = file.read(10); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2599 |
QVERIFY(ret.isEmpty()); |
0 | 2600 |
QVERIFY(file.error() == QFile::NoError); |
2601 |
QVERIFY(file.atEnd()); |
|
2602 |
} |
|
2603 |
||
2604 |
{ |
|
2605 |
QFile file(filename); |
|
2606 |
QVERIFY(file.open(QIODevice::ReadOnly | mode)); |
|
2607 |
bool isSequential = file.isSequential(); |
|
2608 |
if (!isSequential) { |
|
2609 |
QVERIFY(file.seek(245)); |
|
2610 |
QVERIFY(file.atEnd()); |
|
2611 |
} |
|
2612 |
||
2613 |
char buf[10]; |
|
2614 |
int ret = file.readLine(buf, sizeof buf); |
|
2615 |
QCOMPARE(ret, -1); |
|
2616 |
QVERIFY(file.error() == QFile::NoError); |
|
2617 |
QVERIFY(file.atEnd()); |
|
2618 |
||
2619 |
// Do it again to ensure that we get the same result |
|
2620 |
ret = file.readLine(buf, sizeof buf); |
|
2621 |
QCOMPARE(ret, -1); |
|
2622 |
QVERIFY(file.error() == QFile::NoError); |
|
2623 |
QVERIFY(file.atEnd()); |
|
2624 |
} |
|
2625 |
||
2626 |
{ |
|
2627 |
QFile file(filename); |
|
2628 |
QVERIFY(file.open(QIODevice::ReadOnly | mode)); |
|
2629 |
bool isSequential = file.isSequential(); |
|
2630 |
if (!isSequential) { |
|
2631 |
QVERIFY(file.seek(245)); |
|
2632 |
QVERIFY(file.atEnd()); |
|
2633 |
} |
|
2634 |
||
2635 |
QByteArray ret = file.readLine(); |
|
2636 |
QVERIFY(ret.isNull()); |
|
2637 |
QVERIFY(file.error() == QFile::NoError); |
|
2638 |
QVERIFY(file.atEnd()); |
|
2639 |
||
2640 |
// Do it again to ensure that we get the same result |
|
2641 |
ret = file.readLine(); |
|
2642 |
QVERIFY(ret.isNull()); |
|
2643 |
QVERIFY(file.error() == QFile::NoError); |
|
2644 |
QVERIFY(file.atEnd()); |
|
2645 |
} |
|
2646 |
||
2647 |
{ |
|
2648 |
QFile file(filename); |
|
2649 |
QVERIFY(file.open(QIODevice::ReadOnly | mode)); |
|
2650 |
bool isSequential = file.isSequential(); |
|
2651 |
if (!isSequential) { |
|
2652 |
QVERIFY(file.seek(245)); |
|
2653 |
QVERIFY(file.atEnd()); |
|
2654 |
} |
|
2655 |
||
2656 |
char c; |
|
2657 |
QVERIFY(!file.getChar(&c)); |
|
2658 |
QVERIFY(file.error() == QFile::NoError); |
|
2659 |
QVERIFY(file.atEnd()); |
|
2660 |
||
2661 |
// Do it again to ensure that we get the same result |
|
2662 |
QVERIFY(!file.getChar(&c)); |
|
2663 |
QVERIFY(file.error() == QFile::NoError); |
|
2664 |
QVERIFY(file.atEnd()); |
|
2665 |
} |
|
2666 |
} |
|
2667 |
||
2668 |
void tst_QFile::task167217() |
|
2669 |
{ |
|
2670 |
// Regression introduced in 4.3.0; after a failed stat, pos() could no |
|
2671 |
// longer be calculated correctly. |
|
2672 |
QFile::remove("tmp.txt"); |
|
2673 |
QFile file("tmp.txt"); |
|
2674 |
QVERIFY(!file.exists()); |
|
2675 |
QVERIFY(file.open(QIODevice::Append)); |
|
2676 |
QVERIFY(file.exists()); |
|
2677 |
file.write("qt430", 5); |
|
2678 |
QVERIFY(!file.isSequential()); |
|
2679 |
QCOMPARE(file.pos(), qint64(5)); |
|
2680 |
file.remove(); |
|
2681 |
} |
|
2682 |
||
2683 |
#define FILESIZE 65536 * 3 |
|
2684 |
||
2685 |
void tst_QFile::map_data() |
|
2686 |
{ |
|
2687 |
QTest::addColumn<int>("fileSize"); |
|
2688 |
QTest::addColumn<int>("offset"); |
|
2689 |
QTest::addColumn<int>("size"); |
|
2690 |
QTest::addColumn<QFile::FileError>("error"); |
|
2691 |
||
2692 |
QTest::newRow("zero") << FILESIZE << 0 << FILESIZE << QFile::NoError; |
|
2693 |
QTest::newRow("small, but 0") << FILESIZE << 30 << FILESIZE - 30 << QFile::NoError; |
|
2694 |
QTest::newRow("a page") << FILESIZE << 4096 << FILESIZE - 4096 << QFile::NoError; |
|
2695 |
QTest::newRow("+page") << FILESIZE << 5000 << FILESIZE - 5000 << QFile::NoError; |
|
2696 |
QTest::newRow("++page") << FILESIZE << 65576 << FILESIZE - 65576 << QFile::NoError; |
|
2697 |
QTest::newRow("bad size") << FILESIZE << 0 << -1 << QFile::ResourceError; |
|
2698 |
QTest::newRow("bad offset") << FILESIZE << -1 << 1 << QFile::UnspecifiedError; |
|
2699 |
QTest::newRow("zerozero") << FILESIZE << 0 << 0 << QFile::UnspecifiedError; |
|
2700 |
} |
|
2701 |
||
2702 |
void tst_QFile::map() |
|
2703 |
{ |
|
2704 |
QFETCH(int, fileSize); |
|
2705 |
QFETCH(int, offset); |
|
2706 |
QFETCH(int, size); |
|
2707 |
QFETCH(QFile::FileError, error); |
|
2708 |
||
2709 |
QString fileName = QDir::currentPath() + '/' + "qfile_map_testfile"; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2710 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2711 |
#ifdef Q_WS_WINCE |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2712 |
fileName = QFileInfo(fileName).absoluteFilePath(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2713 |
#endif |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2714 |
|
0 | 2715 |
if (QFile::exists(fileName)) { |
2716 |
QVERIFY(QFile::setPermissions(fileName, |
|
2717 |
QFile::WriteOwner | QFile::ReadOwner | QFile::WriteUser | QFile::ReadUser)); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2718 |
QFile::remove(fileName); |
0 | 2719 |
} |
2720 |
QFile file(fileName); |
|
2721 |
||
2722 |
// invalid, not open |
|
2723 |
uchar *memory = file.map(0, size); |
|
2724 |
QVERIFY(!memory); |
|
2725 |
QCOMPARE(file.error(), QFile::PermissionsError); |
|
2726 |
QVERIFY(!file.unmap(memory)); |
|
2727 |
QCOMPARE(file.error(), QFile::PermissionsError); |
|
2728 |
||
2729 |
// make a file |
|
2730 |
QVERIFY(file.open(QFile::ReadWrite)); |
|
2731 |
QVERIFY(file.resize(fileSize)); |
|
2732 |
QVERIFY(file.flush()); |
|
2733 |
file.close(); |
|
2734 |
QVERIFY(file.open(QFile::ReadWrite)); |
|
2735 |
memory = file.map(offset, size); |
|
2736 |
if (error != QFile::NoError) { |
|
2737 |
||
2738 |
QVERIFY(file.error() != QFile::NoError); |
|
2739 |
return; |
|
2740 |
} |
|
2741 |
||
2742 |
QCOMPARE(file.error(), error); |
|
2743 |
QVERIFY(memory); |
|
2744 |
memory[0] = 'Q'; |
|
2745 |
QVERIFY(file.unmap(memory)); |
|
2746 |
QCOMPARE(file.error(), QFile::NoError); |
|
2747 |
||
2748 |
// Verify changes were saved |
|
2749 |
memory = file.map(offset, size); |
|
2750 |
QCOMPARE(file.error(), QFile::NoError); |
|
2751 |
QVERIFY(memory); |
|
2752 |
QVERIFY(memory[0] == 'Q'); |
|
2753 |
QVERIFY(file.unmap(memory)); |
|
2754 |
QCOMPARE(file.error(), QFile::NoError); |
|
2755 |
||
2756 |
// hpux wont let you map multiple times. |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2757 |
#if !defined(Q_OS_HPUX) && !defined(Q_USE_DEPRECATED_MAP_API) && !defined(Q_OS_WINCE) |
0 | 2758 |
// exotic test to make sure that multiple maps work |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2759 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2760 |
// note: windows ce does not reference count mutliple maps |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2761 |
// it's essentially just the same reference but it |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2762 |
// cause a resource lock on the file which prevents it |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2763 |
// from being removed uchar *memory1 = file.map(0, file.size()); |
0 | 2764 |
uchar *memory1 = file.map(0, file.size()); |
2765 |
QCOMPARE(file.error(), QFile::NoError); |
|
2766 |
uchar *memory2 = file.map(0, file.size()); |
|
2767 |
QCOMPARE(file.error(), QFile::NoError); |
|
2768 |
QVERIFY(memory1); |
|
2769 |
QVERIFY(memory2); |
|
2770 |
QVERIFY(file.unmap(memory1)); |
|
2771 |
QCOMPARE(file.error(), QFile::NoError); |
|
2772 |
QVERIFY(file.unmap(memory2)); |
|
2773 |
QCOMPARE(file.error(), QFile::NoError); |
|
2774 |
memory1 = file.map(0, file.size()); |
|
2775 |
QCOMPARE(file.error(), QFile::NoError); |
|
2776 |
QVERIFY(memory1); |
|
2777 |
QVERIFY(file.unmap(memory1)); |
|
2778 |
QCOMPARE(file.error(), QFile::NoError); |
|
2779 |
#endif |
|
2780 |
||
2781 |
file.close(); |
|
2782 |
||
2783 |
#if defined(Q_OS_SYMBIAN) |
|
2784 |
if (false) // No permissions for user makes no sense in Symbian |
|
2785 |
#elif defined(Q_OS_UNIX) |
|
2786 |
if (::getuid() != 0) |
|
2787 |
// root always has permissions |
|
2788 |
#endif |
|
2789 |
{ |
|
2790 |
// Change permissions on a file, just to confirm it would fail |
|
2791 |
QFile::Permissions originalPermissions = file.permissions(); |
|
2792 |
QVERIFY(file.setPermissions(QFile::ReadOther)); |
|
2793 |
QVERIFY(!file.open(QFile::ReadWrite)); |
|
2794 |
memory = file.map(offset, size); |
|
2795 |
QCOMPARE(file.error(), QFile::PermissionsError); |
|
2796 |
QVERIFY(!memory); |
|
2797 |
QVERIFY(file.setPermissions(originalPermissions)); |
|
2798 |
} |
|
2799 |
QVERIFY(file.remove()); |
|
2800 |
} |
|
2801 |
||
2802 |
void tst_QFile::mapResource_data() |
|
2803 |
{ |
|
2804 |
QTest::addColumn<int>("offset"); |
|
2805 |
QTest::addColumn<int>("size"); |
|
2806 |
QTest::addColumn<QFile::FileError>("error"); |
|
2807 |
QTest::addColumn<QString>("fileName"); |
|
2808 |
||
2809 |
QString validFile = ":/tst_qfileinfo/resources/file1.ext1"; |
|
2810 |
QString invalidFile = ":/tst_qfileinfo/resources/filefoo.ext1"; |
|
2811 |
||
2812 |
for (int i = 0; i < 2; ++i) { |
|
2813 |
QString file = (i == 0) ? validFile : invalidFile; |
|
2814 |
QTest::newRow("0, 0") << 0 << 0 << QFile::UnspecifiedError << file; |
|
2815 |
QTest::newRow("0, BIG") << 0 << 4096 << QFile::UnspecifiedError << file; |
|
2816 |
QTest::newRow("-1, 0") << -1 << 0 << QFile::UnspecifiedError << file; |
|
2817 |
QTest::newRow("0, -1") << 0 << -1 << QFile::UnspecifiedError << file; |
|
2818 |
} |
|
2819 |
||
2820 |
QTest::newRow("0, 1") << 0 << 1 << QFile::NoError << validFile; |
|
2821 |
} |
|
2822 |
||
2823 |
void tst_QFile::mapResource() |
|
2824 |
{ |
|
2825 |
QFETCH(QString, fileName); |
|
2826 |
QFETCH(int, offset); |
|
2827 |
QFETCH(int, size); |
|
2828 |
QFETCH(QFile::FileError, error); |
|
2829 |
||
2830 |
QFile file(fileName); |
|
2831 |
uchar *memory = file.map(offset, size); |
|
2832 |
QCOMPARE(file.error(), error); |
|
2833 |
QVERIFY((error == QFile::NoError) ? (memory != 0) : (memory == 0)); |
|
2834 |
if (error == QFile::NoError) |
|
2835 |
QCOMPARE(QString(memory[0]), QString::number(offset + 1)); |
|
2836 |
QVERIFY(file.unmap(memory)); |
|
2837 |
} |
|
2838 |
||
2839 |
void tst_QFile::mapOpenMode_data() |
|
2840 |
{ |
|
2841 |
QTest::addColumn<int>("openMode"); |
|
2842 |
||
2843 |
QTest::newRow("ReadOnly") << int(QIODevice::ReadOnly); |
|
2844 |
//QTest::newRow("WriteOnly") << int(QIODevice::WriteOnly); // this doesn't make sense |
|
2845 |
QTest::newRow("ReadWrite") << int(QIODevice::ReadWrite); |
|
2846 |
QTest::newRow("ReadOnly,Unbuffered") << int(QIODevice::ReadOnly | QIODevice::Unbuffered); |
|
2847 |
QTest::newRow("ReadWrite,Unbuffered") << int(QIODevice::ReadWrite | QIODevice::Unbuffered); |
|
2848 |
} |
|
2849 |
||
2850 |
void tst_QFile::mapOpenMode() |
|
2851 |
{ |
|
2852 |
QFETCH(int, openMode); |
|
2853 |
static const qint64 fileSize = 4096; |
|
2854 |
QByteArray pattern(fileSize, 'A'); |
|
2855 |
||
2856 |
QString fileName = QDir::currentPath() + '/' + "qfile_map_testfile"; |
|
2857 |
if (QFile::exists(fileName)) { |
|
2858 |
QVERIFY(QFile::setPermissions(fileName, |
|
2859 |
QFile::WriteOwner | QFile::ReadOwner | QFile::WriteUser | QFile::ReadUser)); |
|
2860 |
QFile::remove(fileName); |
|
2861 |
} |
|
2862 |
QFile file(fileName); |
|
2863 |
||
2864 |
// make a file |
|
2865 |
QVERIFY(file.open(QFile::ReadWrite)); |
|
2866 |
QVERIFY(file.write(pattern)); |
|
2867 |
QVERIFY(file.flush()); |
|
2868 |
file.close(); |
|
2869 |
||
2870 |
// open according to our mode |
|
2871 |
QVERIFY(file.open(QIODevice::OpenMode(openMode))); |
|
2872 |
||
2873 |
uchar *memory = file.map(0, fileSize); |
|
2874 |
QVERIFY(memory); |
|
2875 |
QVERIFY(memcmp(memory, pattern, fileSize) == 0); |
|
2876 |
||
2877 |
if (openMode & QIODevice::WriteOnly) { |
|
2878 |
// try to write to the file |
|
2879 |
*memory = 'a'; |
|
2880 |
file.unmap(memory); |
|
2881 |
file.close(); |
|
2882 |
file.open(QIODevice::OpenMode(openMode)); |
|
2883 |
file.seek(0); |
|
2884 |
char c; |
|
2885 |
QVERIFY(file.getChar(&c)); |
|
2886 |
QCOMPARE(c, 'a'); |
|
2887 |
} |
|
2888 |
||
2889 |
file.close(); |
|
2890 |
} |
|
2891 |
||
2892 |
void tst_QFile::openDirectory() |
|
2893 |
{ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2894 |
QFile f1(SRCDIR "resources"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2895 |
// it's a directory, it must exist |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2896 |
QVERIFY(f1.exists()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2897 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2898 |
// ...but not be openable |
0 | 2899 |
QVERIFY(!f1.open(QIODevice::ReadOnly)); |
2900 |
f1.close(); |
|
2901 |
QVERIFY(!f1.open(QIODevice::ReadOnly|QIODevice::Unbuffered)); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2902 |
f1.close(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2903 |
QVERIFY(!f1.open(QIODevice::ReadWrite)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2904 |
f1.close(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2905 |
QVERIFY(!f1.open(QIODevice::WriteOnly)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2906 |
f1.close(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2907 |
QVERIFY(!f1.open(QIODevice::WriteOnly|QIODevice::Unbuffered)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2908 |
f1.close(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2909 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2910 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2911 |
void tst_QFile::openStandardStreamsFileDescriptors() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2912 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2913 |
#ifdef Q_WS_WINCE |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2914 |
//allthough Windows CE (not mobile!) has functions that allow redirecting |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2915 |
//the standard file descriptors to a file (see SetStdioPathW/GetStdioPathW) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2916 |
//it does not have functions to simply open them like below . |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2917 |
QSKIP("Opening standard streams on Windows CE via descriptor not implemented", SkipAll); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2918 |
#endif |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2919 |
// Using file descriptors |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2920 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2921 |
QFile in; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2922 |
in.open(STDIN_FILENO, QIODevice::ReadOnly); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2923 |
QCOMPARE( in.pos(), (qint64)0 ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2924 |
QCOMPARE( in.size(), (qint64)0 ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2925 |
QVERIFY( in.isSequential() ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2926 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2927 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2928 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2929 |
QFile out; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2930 |
out.open(STDOUT_FILENO, QIODevice::WriteOnly); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2931 |
QCOMPARE( out.pos(), (qint64)0 ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2932 |
QCOMPARE( out.size(), (qint64)0 ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2933 |
QVERIFY( out.isSequential() ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2934 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2935 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2936 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2937 |
QFile err; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2938 |
err.open(STDERR_FILENO, QIODevice::WriteOnly); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2939 |
QCOMPARE( err.pos(), (qint64)0 ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2940 |
QCOMPARE( err.size(), (qint64)0 ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2941 |
QVERIFY( err.isSequential() ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2942 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2943 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2944 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2945 |
void tst_QFile::openStandardStreamsBufferedStreams() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2946 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2947 |
#if defined (Q_OS_WIN) || defined(Q_OS_SYMBIAN) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2948 |
QSKIP("Unix only test.", SkipAll); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2949 |
#endif |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2950 |
// Using streams |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2951 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2952 |
QFile in; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2953 |
in.open(stdin, QIODevice::ReadOnly); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2954 |
QCOMPARE( in.pos(), (qint64)0 ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2955 |
QCOMPARE( in.size(), (qint64)0 ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2956 |
QVERIFY( in.isSequential() ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2957 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2958 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2959 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2960 |
QFile out; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2961 |
out.open(stdout, QIODevice::WriteOnly); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2962 |
QCOMPARE( out.pos(), (qint64)0 ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2963 |
QCOMPARE( out.size(), (qint64)0 ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2964 |
QVERIFY( out.isSequential() ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2965 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2966 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2967 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2968 |
QFile err; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2969 |
err.open(stderr, QIODevice::WriteOnly); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2970 |
QCOMPARE( err.pos(), (qint64)0 ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2971 |
QCOMPARE( err.size(), (qint64)0 ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2972 |
QVERIFY( err.isSequential() ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2973 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2974 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2975 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2976 |
void tst_QFile::openStandardStreams() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2977 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2978 |
openStandardStreamsFileDescriptors(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2979 |
openStandardStreamsBufferedStreams(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2980 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2981 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2982 |
void tst_QFile::writeNothing() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2983 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2984 |
for (int i = 0; i < 3; ++i) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2985 |
QFile file("file.txt"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2986 |
QVERIFY( openFile(file, QIODevice::WriteOnly | QIODevice::Unbuffered, FileType(i)) ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2987 |
QVERIFY( 0 == file.write((char *)0, 0) ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2988 |
QCOMPARE( file.error(), QFile::NoError ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2989 |
closeFile(file); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2990 |
} |
0 | 2991 |
} |
2992 |
||
2993 |
QTEST_MAIN(tst_QFile) |
|
2994 |
#include "tst_qfile.moc" |