comparison ui/tests/common.cpp @ 243:4b67cc2d4dad

Merged
author Sascha Wilde <wilde@intevation.de>
date Fri, 28 Mar 2014 18:38:34 +0100
parents c05e126b0b9e
children 17e1c8f37d72
comparison
equal deleted inserted replaced
242:809eaca3898c 243:4b67cc2d4dad
1 #include <QString>
2 #include <QTemporaryFile>
3 #include <QDebug>
4 #include "common.h"
5
6 QString getRandomDataFile(size_t size, const QDir &inDir)
7 {
8 QTemporaryFile *tmpfile;
9 if (inDir != QDir()) {
10 tmpfile = new QTemporaryFile(inDir.path() + "/downloadertest");
11 } else {
12 tmpfile = new QTemporaryFile();
13 }
14 tmpfile->setAutoRemove(false);
15 tmpfile->open();
16 size_t bufsize = 1024 * 1024;
17 if (bufsize > size) {
18 bufsize = size;
19 }
20 char buf[bufsize];
21
22 for (size_t i = 0; i < bufsize; i++) {
23 buf[i] = (char) qrand() % 255;
24 }
25
26 size_t bytesWritten=0;
27 int retval = 0;
28 do {
29 size_t toWrite = size - bytesWritten;
30 if (toWrite < bufsize) {
31 retval = tmpfile->write(buf, toWrite);
32 } else {
33 retval = tmpfile->write(buf, bufsize);
34 }
35 bytesWritten += retval;
36 } while (retval != -1 && bytesWritten < size);
37
38 tmpfile->close();
39 QString ret = tmpfile->fileName();
40 delete tmpfile;
41 return ret;
42 }

http://wald.intevation.org/projects/trustbridge/