blob: 5632576a41b40c4e97d2b48ad43cf09a355a7d8d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
/** \file copyEngine.cpp
\brief Define the copy engine
*/
#include "copyEngineUnitTester.h"
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
copyEngineUnitTester::copyEngineUnitTester(const QString &path,const QList<SupportedTest> &tests)
{
this->path=path;
connect(&timer,&QTimer::timeout,this,©EngineUnitTester::initialize,Qt::QueuedConnection);
srand ( time(NULL) );
}
copyEngineUnitTester::~copyEngineUnitTester()
{
rmpath(path);
}
void copyEngineUnitTester::errorSlot()
{
}
void copyEngineUnitTester::collisionSlot()
{
}
void copyEngineUnitTester::initialize()
{
initializeSource();
}
void copyEngineUnitTester::initializeSource()
{
QDir dir(path);
dir.mkpath(path);
dir.mkpath(path+"/source/");
dir.mkpath(path+"/destination/");
}
bool copyEngineUnitTester::mkFile(const QString &dir,const quint16 &minSize,const quint16 &maxSize)
{
QString name;
int index=0;
while(index<(16/4))
{
name+=QString::number(rand()%10000);
index++;
}
QFile file(dir+"/"+name);
if(file.open(QIODevice::WriteOnly))
{
int size=minSize+(rand()%(maxSize-minSize));
int index=0;
QByteArray byte;
while(index<size)
{
byte[0]=rand()%256;
file.write(byte);
index++;
}
file.close();
return true;
}
else
{
qDebug() << file.errorString();
return false;
}
}
/** remplace QDir::rmpath() because it return false if the folder not exists
and seam bug with parent folder */
bool copyEngineUnitTester::rmpath(const QDir &dir)
{
if(!dir.exists())
return true;
bool allHaveWork=true;
QFileInfoList list = dir.entryInfoList(QDir::AllEntries|QDir::NoDotAndDotDot|QDir::Hidden|QDir::System,QDir::DirsFirst);
for (int i = 0; i < list.size(); ++i)
{
QFileInfo fileInfo(list.at(i));
if(!fileInfo.isDir())
{
ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Warning,"found a file: "+fileInfo.fileName());
allHaveWork=false;
}
else
{
//return the fonction for scan the new folder
if(!rmpath(dir.absolutePath()+'/'+fileInfo.fileName()+'/'))
allHaveWork=false;
}
}
if(!allHaveWork)
return allHaveWork;
allHaveWork=dir.rmdir(dir.absolutePath());
if(!allHaveWork)
ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Warning,"unable to remove the folder: "+dir.absolutePath());
return allHaveWork;
}
|