@@ -116,9 +116,13 @@ class MessageHandlerSetter
116
116
*/
117
117
void tst_QDebug::warningWithoutDebug () const
118
118
{
119
+ QString file, function;
120
+ int line = 0 ;
119
121
MessageHandlerSetter mhs (myMessageHandler);
120
122
{ qWarning () << " A qWarning() message" ; }
121
- QString file = __FILE__; int line = __LINE__ - 1 ; QString function = Q_FUNC_INFO;
123
+ #ifndef QT_NO_MESSAGELOGCONTEXT
124
+ file = __FILE__; line = __LINE__ - 2 ; function = Q_FUNC_INFO;
125
+ #endif
122
126
QCOMPARE (s_msgType, QtWarningMsg);
123
127
QCOMPARE (s_msg, QString::fromLatin1 (" A qWarning() message" ));
124
128
QCOMPARE (QString::fromLatin1 (s_file), file);
@@ -131,9 +135,13 @@ void tst_QDebug::warningWithoutDebug() const
131
135
*/
132
136
void tst_QDebug::criticalWithoutDebug () const
133
137
{
138
+ QString file, function;
139
+ int line = 0 ;
134
140
MessageHandlerSetter mhs (myMessageHandler);
135
141
{ qCritical () << " A qCritical() message" ; }
136
- QString file = __FILE__; int line = __LINE__ - 1 ; QString function = Q_FUNC_INFO;
142
+ #ifndef QT_NO_MESSAGELOGCONTEXT
143
+ file = __FILE__; line = __LINE__ - 2 ; function = Q_FUNC_INFO;
144
+ #endif
137
145
QCOMPARE (s_msgType, QtCriticalMsg);
138
146
QCOMPARE (s_msg, QString::fromLatin1 (" A qCritical() message" ));
139
147
QCOMPARE (QString::fromLatin1 (s_file), file);
@@ -143,9 +151,13 @@ void tst_QDebug::criticalWithoutDebug() const
143
151
144
152
void tst_QDebug::debugWithBool () const
145
153
{
154
+ QString file, function;
155
+ int line = 0 ;
146
156
MessageHandlerSetter mhs (myMessageHandler);
147
157
{ qDebug () << false << true ; }
148
- QString file = __FILE__; int line = __LINE__ - 1 ; QString function = Q_FUNC_INFO;
158
+ #ifndef QT_NO_MESSAGELOGCONTEXT
159
+ file = __FILE__; line = __LINE__ - 2 ; function = Q_FUNC_INFO;
160
+ #endif
149
161
QCOMPARE (s_msgType, QtDebugMsg);
150
162
QCOMPARE (s_msg, QString::fromLatin1 (" false true" ));
151
163
QCOMPARE (QString::fromLatin1 (s_file), file);
@@ -291,6 +303,8 @@ void tst_QDebug::stateSaver() const
291
303
292
304
void tst_QDebug::veryLongWarningMessage () const
293
305
{
306
+ QString file, function;
307
+ int line = 0 ;
294
308
MessageHandlerSetter mhs (myMessageHandler);
295
309
QString test;
296
310
{
@@ -299,7 +313,9 @@ void tst_QDebug::veryLongWarningMessage() const
299
313
test.append (part);
300
314
qWarning (" Test output:\n %s\n end" , qPrintable (test));
301
315
}
302
- QString file = __FILE__; int line = __LINE__ - 2 ; QString function = Q_FUNC_INFO;
316
+ #ifndef QT_NO_MESSAGELOGCONTEXT
317
+ file = __FILE__; line = __LINE__ - 3 ; function = Q_FUNC_INFO;
318
+ #endif
303
319
QCOMPARE (s_msgType, QtWarningMsg);
304
320
QCOMPARE (s_msg, QString::fromLatin1 (" Test output:\n " )+test+QString::fromLatin1 (" \n end" ));
305
321
QCOMPARE (QString::fromLatin1 (s_file), file);
@@ -309,13 +325,17 @@ void tst_QDebug::veryLongWarningMessage() const
309
325
310
326
void tst_QDebug::qDebugQChar () const
311
327
{
328
+ QString file, function;
329
+ int line = 0 ;
312
330
MessageHandlerSetter mhs (myMessageHandler);
313
331
{
314
332
QDebug d = qDebug ();
315
333
d << QChar (' f' );
316
334
d.nospace ().noquote () << QChar (' o' ) << QChar (' o' );
317
335
}
318
- QString file = __FILE__; int line = __LINE__ - 4 ; QString function = Q_FUNC_INFO;
336
+ #ifndef QT_NO_MESSAGELOGCONTEXT
337
+ file = __FILE__; line = __LINE__ - 5 ; function = Q_FUNC_INFO;
338
+ #endif
319
339
QCOMPARE (s_msgType, QtDebugMsg);
320
340
QCOMPARE (s_msg, QString::fromLatin1 (" 'f' oo" ));
321
341
QCOMPARE (QString::fromLatin1 (s_file), file);
@@ -328,12 +348,16 @@ void tst_QDebug::qDebugQStringRef() const
328
348
{
329
349
/* Use a basic string. */
330
350
{
351
+ QString file, function;
352
+ int line = 0 ;
331
353
const QString in (QLatin1String (" input" ));
332
354
const QStringRef inRef (&in);
333
355
334
356
MessageHandlerSetter mhs (myMessageHandler);
335
357
{ qDebug () << inRef; }
336
- QString file = __FILE__; int line = __LINE__ - 1 ; QString function = Q_FUNC_INFO;
358
+ #ifndef QT_NO_MESSAGELOGCONTEXT
359
+ file = __FILE__; line = __LINE__ - 2 ; function = Q_FUNC_INFO;
360
+ #endif
337
361
QCOMPARE (s_msgType, QtDebugMsg);
338
362
QCOMPARE (s_msg, QString::fromLatin1 (" \" input\" " ));
339
363
QCOMPARE (QString::fromLatin1 (s_file), file);
@@ -343,11 +367,16 @@ void tst_QDebug::qDebugQStringRef() const
343
367
344
368
/* Use a null QStringRef. */
345
369
{
370
+ QString file, function;
371
+ int line = 0 ;
372
+
346
373
const QStringRef inRef;
347
374
348
375
MessageHandlerSetter mhs (myMessageHandler);
349
376
{ qDebug () << inRef; }
350
- QString file = __FILE__; int line = __LINE__ - 1 ; QString function = Q_FUNC_INFO;
377
+ #ifndef QT_NO_MESSAGELOGCONTEXT
378
+ file = __FILE__; line = __LINE__ - 2 ; function = Q_FUNC_INFO;
379
+ #endif
351
380
QCOMPARE (s_msgType, QtDebugMsg);
352
381
QCOMPARE (s_msg, QString::fromLatin1 (" \"\" " ));
353
382
QCOMPARE (QString::fromLatin1 (s_file), file);
@@ -358,13 +387,17 @@ void tst_QDebug::qDebugQStringRef() const
358
387
359
388
void tst_QDebug::qDebugQLatin1String () const
360
389
{
390
+ QString file, function;
391
+ int line = 0 ;
361
392
MessageHandlerSetter mhs (myMessageHandler);
362
393
{
363
394
QDebug d = qDebug ();
364
395
d << QLatin1String (" foo" ) << QLatin1String (" " ) << QLatin1String (" barbaz" , 3 );
365
396
d.nospace ().noquote () << QLatin1String (" baz" );
366
397
}
367
- QString file = __FILE__; int line = __LINE__ - 4 ; QString function = Q_FUNC_INFO;
398
+ #ifndef QT_NO_MESSAGELOGCONTEXT
399
+ file = __FILE__; line = __LINE__ - 5 ; function = Q_FUNC_INFO;
400
+ #endif
368
401
QCOMPARE (s_msgType, QtDebugMsg);
369
402
QCOMPARE (s_msg, QString::fromLatin1 (" \" foo\" \"\" \" bar\" baz" ));
370
403
QCOMPARE (QString::fromLatin1 (s_file), file);
@@ -374,13 +407,17 @@ void tst_QDebug::qDebugQLatin1String() const
374
407
375
408
void tst_QDebug::qDebugQByteArray () const
376
409
{
410
+ QString file, function;
411
+ int line = 0 ;
377
412
MessageHandlerSetter mhs (myMessageHandler);
378
413
{
379
414
QDebug d = qDebug ();
380
415
d << QByteArrayLiteral (" foo" ) << QByteArrayLiteral (" " ) << QByteArray (" barbaz" , 3 );
381
416
d.nospace ().noquote () << QByteArrayLiteral (" baz" );
382
417
}
383
- QString file = __FILE__; int line = __LINE__ - 4 ; QString function = Q_FUNC_INFO;
418
+ #ifndef QT_NO_MESSAGELOGCONTEXT
419
+ file = __FILE__; line = __LINE__ - 5 ; function = Q_FUNC_INFO;
420
+ #endif
384
421
QCOMPARE (s_msgType, QtDebugMsg);
385
422
QCOMPARE (s_msg, QString::fromLatin1 (" \" foo\" \"\" \" bar\" baz" ));
386
423
QCOMPARE (QString::fromLatin1 (s_file), file);
@@ -397,11 +434,15 @@ Q_DECLARE_FLAGS(TestFlags, TestEnum)
397
434
398
435
void tst_QDebug::qDebugQFlags() const
399
436
{
437
+ QString file, function;
438
+ int line = 0 ;
400
439
QFlags<TestEnum> flags (Flag1 | Flag2);
401
440
402
441
MessageHandlerSetter mhs (myMessageHandler);
403
442
{ qDebug () << flags; }
404
- QString file = __FILE__; int line = __LINE__ - 1 ; QString function = Q_FUNC_INFO;
443
+ #ifndef QT_NO_MESSAGELOGCONTEXT
444
+ file = __FILE__; line = __LINE__ - 2 ; function = Q_FUNC_INFO;
445
+ #endif
405
446
QCOMPARE (s_msgType, QtDebugMsg);
406
447
QCOMPARE (s_msg, QString::fromLatin1 (" QFlags(0x1|0x10)" ));
407
448
QCOMPARE (QString::fromLatin1 (s_file), file);
@@ -412,9 +453,13 @@ void tst_QDebug::qDebugQFlags() const
412
453
413
454
void tst_QDebug::textStreamModifiers () const
414
455
{
456
+ QString file, function;
457
+ int line = 0 ;
415
458
MessageHandlerSetter mhs (myMessageHandler);
416
459
{ qDebug () << hex << short (0xf ) << int (0xf ) << unsigned (0xf ) << long (0xf ) << qint64 (0xf ) << quint64 (0xf ); }
417
- QString file = __FILE__; int line = __LINE__ - 1 ; QString function = Q_FUNC_INFO;
460
+ #ifndef QT_NO_MESSAGELOGCONTEXT
461
+ file = __FILE__; line = __LINE__ - 2 ; function = Q_FUNC_INFO;
462
+ #endif
418
463
QCOMPARE (s_msgType, QtDebugMsg);
419
464
QCOMPARE (s_msg, QString::fromLatin1 (" f f f f f f" ));
420
465
QCOMPARE (QString::fromLatin1 (s_file), file);
@@ -424,13 +469,17 @@ void tst_QDebug::textStreamModifiers() const
424
469
425
470
void tst_QDebug::resetFormat () const
426
471
{
472
+ QString file, function;
473
+ int line = 0 ;
427
474
MessageHandlerSetter mhs (myMessageHandler);
428
475
{
429
476
QDebug d = qDebug ();
430
477
d.nospace ().noquote () << hex << int (0xf );
431
478
d.resetFormat () << int (0xf ) << QStringLiteral (" foo" );
432
479
}
433
- QString file = __FILE__; int line = __LINE__ - 4 ; QString function = Q_FUNC_INFO;
480
+ #ifndef QT_NO_MESSAGELOGCONTEXT
481
+ file = __FILE__; line = __LINE__ - 5 ; function = Q_FUNC_INFO;
482
+ #endif
434
483
QCOMPARE (s_msgType, QtDebugMsg);
435
484
QCOMPARE (s_msg, QString::fromLatin1 (" f15 \" foo\" " ));
436
485
QCOMPARE (QString::fromLatin1 (s_file), file);
0 commit comments