blob: b5aef12d06c029cf86ca216668f9d5f35a46da12 (
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
|
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include <QDebug>
#include <QRandomGenerator>
#include <QtCore/qiodevice.h>
#include <QtTest>
#include <utils/commandline.h>
#include <utils/devicefileaccess.h>
#include <utils/hostosinfo.h>
#include <utils/link.h>
//TESTED_COMPONENT=src/libs/utils
using namespace Utils;
namespace QTest {
template<>
char *toString(const FilePath &filePath)
{
return qstrdup(filePath.toString().toLocal8Bit().constData());
}
} // namespace QTest
class TestDFA : public UnixDeviceFileAccess
{
public:
using UnixDeviceFileAccess::UnixDeviceFileAccess;
virtual RunResult runInShell(const CommandLine &cmdLine,
const QByteArray &inputData = {}) const override
{
QProcess p;
p.setProgram(cmdLine.executable().toString());
p.setArguments(cmdLine.splitArguments());
p.setProcessChannelMode(QProcess::SeparateChannels);
p.start();
p.waitForStarted();
if (inputData.size() > 0) {
p.write(inputData);
p.closeWriteChannel();
}
p.waitForFinished();
return {p.exitCode(), p.readAllStandardOutput(), p.readAllStandardError()};
}
};
class tst_unixdevicefileaccess : public QObject
{
Q_OBJECT
private slots:
void initTestCase()
{
if (HostOsInfo::isWindowsHost())
QSKIP("This test is only for Unix hosts");
m_fileSizeTestFile.writeFileContents(QByteArray(1024, 'a'));
}
void fileSize()
{
const auto size = m_dfaPtr->fileSize(m_fileSizeTestFile);
QCOMPARE(size, 1024);
}
private:
TestDFA m_dfa;
DeviceFileAccess *m_dfaPtr = &m_dfa;
QTemporaryDir m_tempDir;
FilePath m_fileSizeTestFile = FilePath::fromString(m_tempDir.filePath("size-test"));
};
QTEST_GUILESS_MAIN(tst_unixdevicefileaccess)
#include "tst_unixdevicefileaccess.moc"
|