1
1
#include " cucumber-cpp/internal/drivers/QtTestDriver.hpp"
2
2
3
+ #include < QTest>
3
4
#include < QTemporaryFile>
4
5
#include < QTextStream>
5
- #include < QtTest/QtTest>
6
6
7
7
namespace cucumber {
8
8
namespace internal {
9
9
10
10
/* *
11
- * Wraps the QTemporaryFile creation
11
+ * Wraps the QTemporaryFile for Windows.
12
12
*
13
- * On Windows the file could not be written as long as QTemporaryFile owner of the file .
13
+ * On Windows. the file can not be written as long as QTemporaryFile keeps it open .
14
14
*/
15
15
class TemporaryFileWrapper {
16
16
public:
17
- static TemporaryFileWrapper create () {
18
- QTemporaryFile tempFile (QString (" %1/%2_%3" )
19
- .arg (
20
- QDir::tempPath (),
21
- qApp->applicationName ().isEmpty () ? " qt_temp"
22
- : qApp->applicationName ()
23
- )
24
- .arg (qApp->applicationPid ()));
25
-
26
- if (!tempFile.open ()) {
27
- return {};
28
- }
29
-
30
- return {tempFile.fileName () + " .txt" };
31
- }
32
-
33
- TemporaryFileWrapper () :
34
- filename{} {
35
- }
36
-
37
- TemporaryFileWrapper (QString filename) :
38
- filename{filename} {
39
- }
40
-
41
17
~TemporaryFileWrapper () {
42
18
QFile::remove (filename);
43
19
}
@@ -59,11 +35,19 @@ class TemporaryFileWrapper {
59
35
}
60
36
61
37
private:
62
- QString filename;
38
+ const QString filename{getTmpFileName ()};
39
+
40
+ static QString getTmpFileName () {
41
+ QTemporaryFile tempFile{};
42
+ if (!tempFile.open ()) {
43
+ return {};
44
+ }
45
+ return tempFile.fileName () + " .txt" ;
46
+ }
63
47
};
64
48
65
49
const InvokeResult QtTestStep::invokeStepBody () {
66
- const auto file = TemporaryFileWrapper::create () ;
50
+ const TemporaryFileWrapper file{} ;
67
51
if (!file.exists ()) {
68
52
return InvokeResult::failure (" Unable to open temporary file needed for this test" );
69
53
}
0 commit comments