@@ -29,45 +29,52 @@ DocumentTest::DocumentTest()
29
29
30
30
void DocumentTest::testDocumentProperty ()
31
31
{
32
+ QBuffer device;
33
+ device.open (QIODevice::WriteOnly);
34
+
32
35
Document xlsx1;
33
36
xlsx1.setDocumentProperty (" creator" , " Debao" );
34
37
xlsx1.setDocumentProperty (" company" , " Test" );
35
- xlsx1.saveAs (" test.xlsx " );
38
+ xlsx1.saveAs (&device );
36
39
37
- Document xlsx2 (" test.xlsx" );
40
+ device.open (QIODevice::ReadOnly);
41
+ Document xlsx2 (&device);
38
42
QCOMPARE (xlsx2.documentProperty (" creator" ), QString (" Debao" ));
39
43
QCOMPARE (xlsx2.documentProperty (" company" ), QString (" Test" ));
40
-
41
- QFile::remove (" test.xlsx" );
42
44
}
43
45
44
46
void DocumentTest::testReadWriteString ()
45
47
{
48
+ QBuffer device;
49
+ device.open (QIODevice::WriteOnly);
50
+
46
51
Document xlsx1;
47
52
xlsx1.write (" A1" , " Hello Qt!" );
48
53
Format format;
49
54
format.setFontColor (Qt::blue);
50
55
format.setBorderStyle (Format::BorderDashDotDot);
51
56
format.setFillPattern (Format::PatternSolid);
52
57
xlsx1.write (" A2" , " Hello Qt again!" , format);
53
- xlsx1.saveAs (" test.xlsx " );
58
+ xlsx1.saveAs (&device );
54
59
55
- Document xlsx2 (" test.xlsx" );
60
+ device.open (QIODevice::ReadOnly);
61
+ Document xlsx2 (&device);
56
62
QCOMPARE (xlsx2.cellAt (" A1" )->dataType (), Cell::String);
57
63
QCOMPARE (xlsx2.cellAt (" A1" )->value ().toString (), QString (" Hello Qt!" ));
58
64
QCOMPARE (xlsx2.cellAt (" A2" )->dataType (), Cell::String);
59
65
QCOMPARE (xlsx2.cellAt (" A2" )->value ().toString (), QString (" Hello Qt again!" ));
60
- QVERIFY (xlsx2.cellAt (" A2" )->format ().isValid ());
61
- QCOMPARE (xlsx2.cellAt (" A2" )->format ().fontColor (), format.fontColor ());
62
- QCOMPARE (xlsx2.cellAt (" A2" )->format ().leftBorderStyle (), format.leftBorderStyle ());
63
- QCOMPARE (xlsx2.cellAt (" A2" )->format ().fillPattern (), format.fillPattern ());
64
- // QCOMPARE(xlsx2.cellAt("A2")->format(), format);
65
-
66
- QFile::remove (" test.xlsx" );
66
+ Format format2 = xlsx2.cellAt (" A2" )->format ();
67
+ QVERIFY (format2.isValid ());
68
+ // qDebug()<<format2;
69
+ // qDebug()<<format;
70
+ QCOMPARE (format2, format);
67
71
}
68
72
69
73
void DocumentTest::testReadWriteNumeric ()
70
74
{
75
+ QBuffer device;
76
+ device.open (QIODevice::WriteOnly);
77
+
71
78
Document xlsx1;
72
79
xlsx1.write (" A1" , 123 );
73
80
Format format;
@@ -76,53 +83,58 @@ void DocumentTest::testReadWriteNumeric()
76
83
format.setFillPattern (Format::PatternSolid);
77
84
format.setNumberFormatIndex (10 );
78
85
xlsx1.write (" A2" , 12345 , format);
79
- xlsx1.saveAs (" test.xlsx " );
86
+ xlsx1.saveAs (&device );
80
87
81
- Document xlsx2 (" test.xlsx" );
88
+ device.open (QIODevice::ReadOnly);
89
+ Document xlsx2 (&device);
82
90
QCOMPARE (xlsx2.cellAt (" A1" )->dataType (), Cell::Numeric);
83
91
QCOMPARE (xlsx2.cellAt (" A1" )->value ().toDouble (), 123.0 );
84
92
QCOMPARE (xlsx2.cellAt (" A2" )->dataType (), Cell::Numeric);
85
93
QCOMPARE (xlsx2.cellAt (" A2" )->value ().toDouble (), 12345.0 );
86
94
QVERIFY (xlsx2.cellAt (" A2" )->format ().isValid ());
87
95
QCOMPARE (xlsx2.cellAt (" A2" )->format (), format);
88
-
89
- QFile::remove (" test.xlsx" );
90
96
}
91
97
92
98
void DocumentTest::testReadWriteBool ()
93
99
{
100
+ QBuffer device;
101
+ device.open (QIODevice::WriteOnly);
102
+
94
103
Document xlsx1;
95
104
xlsx1.write (" A1" , true );
96
105
Format format;
97
106
format.setFontColor (Qt::blue);
98
107
format.setBorderStyle (Format::BorderDashDotDot);
99
108
format.setFillPattern (Format::PatternSolid);
100
109
xlsx1.write (" A2" , false , format);
101
- xlsx1.saveAs (" test.xlsx " );
110
+ xlsx1.saveAs (&device );
102
111
103
- Document xlsx2 (" test.xlsx" );
112
+ device.open (QIODevice::ReadOnly);
113
+ Document xlsx2 (&device);
104
114
QCOMPARE (xlsx2.cellAt (" A1" )->dataType (), Cell::Boolean );
105
115
QCOMPARE (xlsx2.cellAt (" A1" )->value ().toBool (), true );
106
116
QCOMPARE (xlsx2.cellAt (" A2" )->dataType (), Cell::Boolean );
107
117
QCOMPARE (xlsx2.cellAt (" A2" )->value ().toBool (), false );
108
118
QVERIFY (xlsx2.cellAt (" A2" )->format ().isValid ());
109
119
QCOMPARE (xlsx2.cellAt (" A2" )->format (), format);
110
-
111
- QFile::remove (" test.xlsx" );
112
120
}
113
121
114
122
void DocumentTest::testReadWriteBlank ()
115
123
{
124
+ QBuffer device;
125
+ device.open (QIODevice::WriteOnly);
126
+
116
127
Document xlsx1;
117
128
xlsx1.write (" A1" , QVariant ());
118
129
Format format;
119
130
format.setFontColor (Qt::blue);
120
131
format.setBorderStyle (Format::BorderDashDotDot);
121
132
format.setFillPattern (Format::PatternSolid);
122
133
xlsx1.write (" A2" , QVariant (), format);
123
- xlsx1.saveAs (" test.xlsx " );
134
+ xlsx1.saveAs (&device );
124
135
125
- Document xlsx2 (" test.xlsx" );
136
+ device.open (QIODevice::ReadOnly);
137
+ Document xlsx2 (&device);
126
138
QVERIFY (xlsx2.cellAt (" A1" ));
127
139
QCOMPARE (xlsx2.cellAt (" A1" )->dataType (), Cell::Blank);
128
140
QVERIFY (!xlsx2.cellAt (" A1" )->value ().isValid ());
@@ -131,23 +143,25 @@ void DocumentTest::testReadWriteBlank()
131
143
QVERIFY (!xlsx2.cellAt (" A2" )->value ().isValid ());
132
144
QVERIFY (xlsx2.cellAt (" A2" )->format ().isValid ());
133
145
QCOMPARE (xlsx2.cellAt (" A2" )->format (), format);
134
-
135
- QFile::remove (" test.xlsx" );
136
146
}
137
147
138
148
void DocumentTest::testReadWriteFormula ()
139
149
{
150
+ QBuffer device;
151
+ device.open (QIODevice::WriteOnly);
152
+
140
153
Document xlsx1;
141
154
xlsx1.write (" A1" , " =11+22" );
142
155
Format format;
143
156
format.setFontColor (Qt::blue);
144
157
format.setBorderStyle (Format::BorderDashDotDot);
145
158
format.setFillPattern (Format::PatternSolid);
146
159
xlsx1.write (" A2" , " =22+33" , format);
147
- xlsx1.saveAs (" test.xlsx " );
160
+ xlsx1.saveAs (&device );
148
161
149
162
150
- Document xlsx2 (" test.xlsx" );
163
+ device.open (QIODevice::ReadOnly);
164
+ Document xlsx2 (&device);
151
165
QCOMPARE (xlsx2.cellAt (" A1" )->dataType (), Cell::Formula);
152
166
// QCOMPARE(xlsx2.cellAt("A1")->value().toDouble(), 0.0);
153
167
QCOMPARE (xlsx2.cellAt (" A1" )->formula (), QStringLiteral (" 11+22" ));
@@ -156,12 +170,13 @@ void DocumentTest::testReadWriteFormula()
156
170
QCOMPARE (xlsx2.cellAt (" A2" )->formula (), QStringLiteral (" 22+33" ));
157
171
QVERIFY (xlsx2.cellAt (" A2" )->format ().isValid ());
158
172
QCOMPARE (xlsx2.cellAt (" A2" )->format (), format);
159
-
160
- QFile::remove (" test.xlsx" );
161
173
}
162
174
163
175
void DocumentTest::testReadWriteDateTime ()
164
176
{
177
+ QBuffer device;
178
+ device.open (QIODevice::WriteOnly);
179
+
165
180
Document xlsx1;
166
181
QDateTime dt (QDate (2012 , 11 , 12 ), QTime (6 , 0 ), Qt::UTC);
167
182
@@ -177,10 +192,10 @@ void DocumentTest::testReadWriteDateTime()
177
192
format3.setNumberFormat (" dd/mm/yyyy" );
178
193
xlsx1.write (" A3" , dt, format3);
179
194
180
- xlsx1.saveAs (" test.xlsx" );
181
-
182
- Document xlsx2 (" test.xlsx" );
195
+ xlsx1.saveAs (&device);
183
196
197
+ device.open (QIODevice::ReadOnly);
198
+ Document xlsx2 (&device);
184
199
QCOMPARE (xlsx2.cellAt (" A1" )->dataType (), Cell::Numeric);
185
200
QCOMPARE (xlsx2.cellAt (" A1" )->isDateTime (), true );
186
201
QCOMPARE (xlsx2.cellAt (" A1" )->dateTime (), dt);
@@ -195,9 +210,6 @@ void DocumentTest::testReadWriteDateTime()
195
210
QCOMPARE (xlsx2.cellAt (" A3" )->isDateTime (), true );
196
211
QCOMPARE (xlsx2.cellAt (" A3" )->dateTime (), dt);
197
212
QCOMPARE (xlsx2.cellAt (" A3" )->format ().numberFormat (), QString (" dd/mm/yyyy" ));
198
-
199
- QFile::remove (" test.xlsx" );
200
-
201
213
}
202
214
203
215
QTEST_APPLESS_MAIN (DocumentTest)
0 commit comments