forked from owncloud/client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestutils.cpp
More file actions
86 lines (73 loc) · 2.27 KB
/
Copy pathtestutils.cpp
File metadata and controls
86 lines (73 loc) · 2.27 KB
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
#include "testutils.h"
#include "creds/httpcredentials.h"
#include "gui/accountmanager.h"
#include <QCoreApplication>
#include <QRandomGenerator>
namespace {
class HttpCredentialsTest : public OCC::HttpCredentials
{
public:
HttpCredentialsTest(const QString &user, const QString &password)
: HttpCredentials(OCC::DetermineAuthTypeJob::AuthType::Basic, user, password)
{
}
void askFromUser() override
{
}
};
}
namespace OCC {
namespace TestUtils {
AccountPtr createDummyAccount()
{
// don't use the account manager to create the account, it would try to use widgets
auto acc = Account::create();
HttpCredentialsTest *cred = new HttpCredentialsTest("testuser", "secret");
acc->setCredentials(cred);
acc->setUrl(QUrl(QStringLiteral("http://localhost/owncloud")));
acc->setDavDisplayName(QStringLiteral("fakename") + acc->uuid().toString());
acc->setServerVersion(QStringLiteral("10.0.0"));
OCC::AccountManager::instance()->addAccount(acc);
return acc;
}
FolderDefinition createDummyFolderDefinition(const QString &path)
{
OCC::FolderDefinition d;
d.localPath = path;
d.targetPath = path;
d.alias = path;
return d;
}
FolderMan *folderMan()
{
static QPointer<FolderMan> man;
if (!man) {
man = new FolderMan;
QObject::connect(QCoreApplication::instance(), &QCoreApplication::aboutToQuit, man, &FolderMan::deleteLater);
};
return man;
}
bool writeRandomFile(const QString &fname, int size)
{
auto rg = QRandomGenerator::global();
const int maxSize = 10 * 10 * 1024;
if (size == -1) {
size = static_cast<int>(rg->generate() % maxSize);
}
QString randString;
for (int i = 0; i < size; i++) {
int r = static_cast<int>(rg->generate() % 128);
randString.append(QChar(r));
}
QFile file(fname);
if (file.open(QIODevice::WriteOnly | QIODevice::Text)) {
QTextStream out(&file);
out << randString;
// optional, as QFile destructor will already do it:
file.close();
return true;
}
return false;
}
}
}