0
+ − 1
/****************************************************************************
+ − 2
**
+ − 3
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+ − 4
** All rights reserved.
+ − 5
** Contact: Nokia Corporation (qt-info@nokia.com)
+ − 6
**
+ − 7
** This file is part of the test suite of the Qt Toolkit.
+ − 8
**
+ − 9
** $QT_BEGIN_LICENSE:LGPL$
+ − 10
** No Commercial Usage
+ − 11
** This file contains pre-release code and may not be distributed.
+ − 12
** You may use this file in accordance with the terms and conditions
+ − 13
** contained in the Technology Preview License Agreement accompanying
+ − 14
** this package.
+ − 15
**
+ − 16
** GNU Lesser General Public License Usage
+ − 17
** Alternatively, this file may be used under the terms of the GNU Lesser
+ − 18
** General Public License version 2.1 as published by the Free Software
+ − 19
** Foundation and appearing in the file LICENSE.LGPL included in the
+ − 20
** packaging of this file. Please review the following information to
+ − 21
** ensure the GNU Lesser General Public License version 2.1 requirements
+ − 22
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+ − 23
**
+ − 24
** In addition, as a special exception, Nokia gives you certain additional
+ − 25
** rights. These rights are described in the Nokia Qt LGPL Exception
+ − 26
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+ − 27
**
+ − 28
** If you have questions regarding the use of this file, please contact
+ − 29
** Nokia at qt-info@nokia.com.
+ − 30
**
+ − 31
**
+ − 32
**
+ − 33
**
+ − 34
**
+ − 35
**
+ − 36
**
+ − 37
**
+ − 38
** $QT_END_LICENSE$
+ − 39
**
+ − 40
****************************************************************************/
+ − 41
+ − 42
+ − 43
+ − 44
#include <QtTest/QtTest>
+ − 45
#include <stdio.h>
+ − 46
#include <qobject.h>
+ − 47
+ − 48
#include "using-namespaces.h"
+ − 49
#include "assign-namespace.h"
+ − 50
#include "no-keywords.h"
+ − 51
#include "single_function_keyword.h"
+ − 52
#include "backslash-newlines.h"
+ − 53
#include "slots-with-void-template.h"
+ − 54
#include "pure-virtual-signals.h"
+ − 55
#include "qinvokable.h"
+ − 56
// msvc and friends crap out on it
+ − 57
#if !defined(Q_CC_GNU) || defined(Q_OS_IRIX) || defined(Q_OS_WIN)
+ − 58
#define SKIP_NEWLINE_TEST
+ − 59
#endif
+ − 60
#if !defined(SKIP_NEWLINE_TEST)
+ − 61
#include "os9-newlines.h"
+ − 62
// msvc and friends crap out on this file too,
+ − 63
// it seems to contain Mac 9 EOLs, and not windows EOLs.
+ − 64
#include "win-newlines.h"
+ − 65
#endif
+ − 66
#include "escapes-in-string-literals.h"
+ − 67
#include "cstyle-enums.h"
+ − 68
+ − 69
+ − 70
#if defined(PARSE_BOOST)
+ − 71
#include "parse-boost.h"
+ − 72
#endif
+ − 73
+ − 74
// No such thing as "long long" in Microsoft's compiler 13.0 and before
+ − 75
#if defined Q_CC_MSVC && _MSC_VER <= 1310
+ − 76
# define NOLONGLONG
+ − 77
#endif
+ − 78
+ − 79
QT_USE_NAMESPACE
+ − 80
+ − 81
struct MyStruct {};
+ − 82
struct MyStruct2 {};
+ − 83
+ − 84
struct SuperClass {};
+ − 85
+ − 86
// Try to avoid inserting for instance a comment with a quote between the following line and the Q_OBJECT
+ − 87
// That will make the test give a false positive.
+ − 88
const char* test_multiple_number_of_escapes = "\\\"";
+ − 89
namespace MyNamespace
+ − 90
{
+ − 91
class TestSuperClass : public QObject
+ − 92
{
+ − 93
Q_OBJECT
+ − 94
public:
+ − 95
inline TestSuperClass() {}
+ − 96
};
+ − 97
}
+ − 98
+ − 99
namespace String
+ − 100
{
+ − 101
typedef QString Type;
+ − 102
}
+ − 103
+ − 104
namespace Int
+ − 105
{
+ − 106
typedef int Type;
+ − 107
}
+ − 108
+ − 109
typedef struct {
+ − 110
int doNotConfuseMoc;
+ − 111
} OldStyleCStruct;
+ − 112
+ − 113
class Sender : public QObject
+ − 114
{
+ − 115
Q_OBJECT
+ − 116
+ − 117
public:
+ − 118
void sendValue(const String::Type& value)
+ − 119
{
+ − 120
emit send(value);
+ − 121
}
+ − 122
void sendValue(const Int::Type& value)
+ − 123
{
+ − 124
emit send(value);
+ − 125
}
+ − 126
+ − 127
signals:
+ − 128
void send(const String::Type&);
+ − 129
void send(const Int::Type&);
+ − 130
};
+ − 131
+ − 132
class Receiver : public QObject
+ − 133
{
+ − 134
Q_OBJECT
+ − 135
public:
+ − 136
Receiver() : stringCallCount(0), intCallCount(0) {}
+ − 137
+ − 138
int stringCallCount;
+ − 139
int intCallCount;
+ − 140
+ − 141
public slots:
+ − 142
void receive(const String::Type&) { stringCallCount++; }
+ − 143
void receive(const Int::Type&) { intCallCount++; }
+ − 144
};
+ − 145
+ − 146
#define MACRO_WITH_POSSIBLE_COMPILER_SPECIFIC_ATTRIBUTES
+ − 147
+ − 148
#define DONT_CONFUSE_MOC(klass) klass
+ − 149
#define DONT_CONFUSE_MOC_EVEN_MORE(klass, dummy, dummy2) klass
+ − 150
+ − 151
Q_DECLARE_METATYPE(MyStruct)
+ − 152
Q_DECLARE_METATYPE(MyStruct*)
+ − 153
+ − 154
namespace myNS {
+ − 155
struct Points
+ − 156
{
+ − 157
Points() : p1(0xBEEF), p2(0xBABE) { }
+ − 158
int p1, p2;
+ − 159
};
+ − 160
}
+ − 161
+ − 162
Q_DECLARE_METATYPE(myNS::Points)
+ − 163
+ − 164
class TestClassinfoWithEscapes: public QObject
+ − 165
{
+ − 166
Q_OBJECT
+ − 167
Q_CLASSINFO("escaped", "\"bar\"")
+ − 168
Q_CLASSINFO("\"escaped\"", "foo")
+ − 169
public slots:
+ − 170
void slotWithAReallyLongName(int)
+ − 171
{ }
+ − 172
};
+ − 173
+ − 174
struct ForwardDeclaredStruct;
+ − 175
+ − 176
struct StructQObject : public QObject
+ − 177
{
+ − 178
Q_OBJECT
+ − 179
public:
+ − 180
void foo(struct ForwardDeclaredStruct *);
+ − 181
};
+ − 182
+ − 183
void StructQObject::foo(struct ForwardDeclaredStruct *)
+ − 184
{
+ − 185
struct Inner {
+ − 186
bool field;
+ − 187
};
+ − 188
+ − 189
struct Inner unusedVariable;
+ − 190
}
+ − 191
+ − 192
class TestClass : public MyNamespace::TestSuperClass, public DONT_CONFUSE_MOC(MyStruct),
+ − 193
public DONT_CONFUSE_MOC_EVEN_MORE(MyStruct2, dummy, ignored)
+ − 194
{
+ − 195
Q_OBJECT
+ − 196
Q_CLASSINFO("help", QT_TR_NOOP("Opening this will let you configure something"))
+ − 197
Q_PROPERTY(short int shortIntProperty READ shortIntProperty)
+ − 198
Q_PROPERTY(unsigned short int unsignedShortIntProperty READ unsignedShortIntProperty)
+ − 199
Q_PROPERTY(signed short int signedShortIntProperty READ signedShortIntProperty)
+ − 200
Q_PROPERTY(long int longIntProperty READ longIntProperty)
+ − 201
Q_PROPERTY(unsigned long int unsignedLongIntProperty READ unsignedLongIntProperty)
+ − 202
Q_PROPERTY(signed long int signedLongIntProperty READ signedLongIntProperty)
+ − 203
Q_PROPERTY(long double longDoubleProperty READ longDoubleProperty)
+ − 204
Q_PROPERTY(myNS::Points points READ points WRITE setPoints)
+ − 205
+ − 206
Q_CLASSINFO("Multi"
+ − 207
"line",
+ − 208
""
+ − 209
"This is a "
+ − 210
"multiline Q_CLASSINFO"
+ − 211
"")
+ − 212
+ − 213
// a really really long string that we have to cut into pieces in the generated stringdata
+ − 214
// table, otherwise msvc craps out
+ − 215
Q_CLASSINFO("D-Bus Introspection", ""
+ − 216
" <interface name=\"org.kde.KCookieServer\" >\n"
+ − 217
" <method name=\"findCookies\" >\n"
+ − 218
" <arg direction=\"in\" type=\"s\" name=\"url\" />\n"
+ − 219
" <arg direction=\"in\" type=\"x\" name=\"windowId\" />\n"
+ − 220
" <arg direction=\"out\" type=\"s\" name=\"cookies\" />\n"
+ − 221
" </method>\n"
+ − 222
" <method name=\"findDomains\" >\n"
+ − 223
" <arg direction=\"out\" type=\"as\" name=\"domains\" />\n"
+ − 224
" </method>\n"
+ − 225
" <method name=\"findCookies\" >\n"
+ − 226
" <arg direction=\"in\" type=\"ai\" name=\"fields\" />\n"
+ − 227
" <arg direction=\"in\" type=\"s\" name=\"domain\" />\n"
+ − 228
" <arg direction=\"in\" type=\"s\" name=\"fqdn\" />\n"
+ − 229
" <arg direction=\"in\" type=\"s\" name=\"path\" />\n"
+ − 230
" <arg direction=\"in\" type=\"s\" name=\"name\" />\n"
+ − 231
" <arg direction=\"out\" type=\"as\" name=\"cookies\" />\n"
+ − 232
" <annotation value=\"QList<int>\" name=\"com.trolltech.QtDBus.QtTypeName.In0\" />\n"
+ − 233
" </method>\n"
+ − 234
" <method name=\"findDOMCookies\" >\n"
+ − 235
" <arg direction=\"in\" type=\"s\" name=\"url\" />\n"
+ − 236
" <arg direction=\"in\" type=\"x\" name=\"windowId\" />\n"
+ − 237
" <arg direction=\"out\" type=\"s\" name=\"cookies\" />\n"
+ − 238
" </method>\n"
+ − 239
" <method name=\"addCookies\" >\n"
+ − 240
" <arg direction=\"in\" type=\"s\" name=\"url\" />\n"
+ − 241
" <arg direction=\"in\" type=\"ay\" name=\"cookieHeader\" />\n"
+ − 242
" <arg direction=\"in\" type=\"x\" name=\"windowId\" />\n"
+ − 243
" </method>\n"
+ − 244
" <method name=\"deleteCookie\" >\n"
+ − 245
" <arg direction=\"in\" type=\"s\" name=\"domain\" />\n"
+ − 246
" <arg direction=\"in\" type=\"s\" name=\"fqdn\" />\n"
+ − 247
" <arg direction=\"in\" type=\"s\" name=\"path\" />\n"
+ − 248
" <arg direction=\"in\" type=\"s\" name=\"name\" />\n"
+ − 249
" </method>\n"
+ − 250
" <method name=\"deleteCookiesFromDomain\" >\n"
+ − 251
" <arg direction=\"in\" type=\"s\" name=\"domain\" />\n"
+ − 252
" </method>\n"
+ − 253
" <method name=\"deleteSessionCookies\" >\n"
+ − 254
" <arg direction=\"in\" type=\"x\" name=\"windowId\" />\n"
+ − 255
" </method>\n"
+ − 256
" <method name=\"deleteSessionCookiesFor\" >\n"
+ − 257
" <arg direction=\"in\" type=\"s\" name=\"fqdn\" />\n"
+ − 258
" <arg direction=\"in\" type=\"x\" name=\"windowId\" />\n"
+ − 259
" </method>\n"
+ − 260
" <method name=\"deleteAllCookies\" />\n"
+ − 261
" <method name=\"addDOMCookies\" >\n"
+ − 262
" <arg direction=\"in\" type=\"s\" name=\"url\" />\n"
+ − 263
" <arg direction=\"in\" type=\"ay\" name=\"cookieHeader\" />\n"
+ − 264
" <arg direction=\"in\" type=\"x\" name=\"windowId\" />\n"
+ − 265
" </method>\n"
+ − 266
" <method name=\"setDomainAdvice\" >\n"
+ − 267
" <arg direction=\"in\" type=\"s\" name=\"url\" />\n"
+ − 268
" <arg direction=\"in\" type=\"s\" name=\"advice\" />\n"
+ − 269
" </method>\n"
+ − 270
" <method name=\"getDomainAdvice\" >\n"
+ − 271
" <arg direction=\"in\" type=\"s\" name=\"url\" />\n"
+ − 272
" <arg direction=\"out\" type=\"s\" name=\"advice\" />\n"
+ − 273
" </method>\n"
+ − 274
" <method name=\"reloadPolicy\" />\n"
+ − 275
" <method name=\"shutdown\" />\n"
+ − 276
" </interface>\n"
+ − 277
"")
+ − 278
+ − 279
public:
+ − 280
inline TestClass() {}
+ − 281
+ − 282
private slots:
+ − 283
inline void dummy1() MACRO_WITH_POSSIBLE_COMPILER_SPECIFIC_ATTRIBUTES {}
+ − 284
inline void dummy2() MACRO_WITH_POSSIBLE_COMPILER_SPECIFIC_ATTRIBUTES const {}
+ − 285
inline void dummy3() const MACRO_WITH_POSSIBLE_COMPILER_SPECIFIC_ATTRIBUTES {}
+ − 286
+ − 287
#ifndef NOLONGLONG
+ − 288
void slotWithULongLong(unsigned long long) {}
+ − 289
void slotWithULongLongP(unsigned long long*) {}
+ − 290
void slotWithULong(unsigned long) {}
+ − 291
void slotWithLongLong(long long) {}
+ − 292
void slotWithLong(long) {}
+ − 293
#endif
+ − 294
+ − 295
void slotWithColonColonType(::Int::Type) {}
+ − 296
+ − 297
TestClass &slotWithReferenceReturnType() { return *this; }
+ − 298
+ − 299
#if (0 && 1) || 1
+ − 300
void expressionEvaluationShortcut1() {}
+ − 301
#endif
+ − 302
#if (1 || 0) && 0
+ − 303
#else
+ − 304
void expressionEvaluationShortcut2() {}
+ − 305
#endif
+ − 306
+ − 307
public slots:
+ − 308
void slotWithArray(const double[3]) {}
+ − 309
void slotWithNamedArray(const double namedArray[3]) {}
+ − 310
void slotWithMultiArray(const double[3][4]) {}
+ − 311
+ − 312
short int shortIntProperty() { return 0; }
+ − 313
unsigned short int unsignedShortIntProperty() { return 0; }
+ − 314
signed short int signedShortIntProperty() { return 0; }
+ − 315
long int longIntProperty() { return 0; }
+ − 316
unsigned long int unsignedLongIntProperty() { return 0; }
+ − 317
signed long int signedLongIntProperty() { return 0; }
+ − 318
long double longDoubleProperty() { return 0.0; }
+ − 319
+ − 320
myNS::Points points() { return m_points; }
+ − 321
void setPoints(myNS::Points points) { m_points = points; }
+ − 322
+ − 323
signals:
+ − 324
void signalWithArray(const double[3]);
+ − 325
void signalWithNamedArray(const double namedArray[3]);
+ − 326
+ − 327
private slots:
+ − 328
// for tst_Moc::preprocessorConditionals
+ − 329
#if 0
+ − 330
void invalidSlot() {}
+ − 331
#else
+ − 332
void slotInElse() {}
+ − 333
#endif
+ − 334
+ − 335
#if 1
+ − 336
void slotInIf() {}
+ − 337
#else
+ − 338
void invalidSlot() {}
+ − 339
#endif
+ − 340
+ − 341
#if 0
+ − 342
void invalidSlot() {}
+ − 343
#elif 0
+ − 344
#else
+ − 345
void slotInLastElse() {}
+ − 346
#endif
+ − 347
+ − 348
#if 0
+ − 349
void invalidSlot() {}
+ − 350
#elif 1
+ − 351
void slotInElif() {}
+ − 352
#else
+ − 353
void invalidSlot() {}
+ − 354
#endif
+ − 355
+ − 356
+ − 357
friend class Receiver; // task #85783
+ − 358
signals:
+ − 359
friend class Sender; // task #85783
+ − 360
+ − 361
public slots:
+ − 362
void const slotWithSillyConst() {}
+ − 363
+ − 364
public:
+ − 365
Q_INVOKABLE void const slotWithSillyConst2() {}
+ − 366
+ − 367
// that one however should be fine
+ − 368
public slots:
+ − 369
void slotWithVoidStar(void *) {}
+ − 370
+ − 371
private:
+ − 372
myNS::Points m_points;
+ − 373
+ − 374
private slots:
+ − 375
inline virtual void blub1() {}
+ − 376
virtual inline void blub2() {}
+ − 377
};
+ − 378
+ − 379
class PropertyTestClass : public QObject
+ − 380
{
+ − 381
Q_OBJECT
+ − 382
public:
+ − 383
+ − 384
enum TestEnum { One, Two, Three };
+ − 385
+ − 386
Q_ENUMS(TestEnum)
+ − 387
};
+ − 388
+ − 389
class PropertyUseClass : public QObject
+ − 390
{
+ − 391
Q_OBJECT
+ − 392
Q_PROPERTY(PropertyTestClass::TestEnum foo READ foo)
+ − 393
public:
+ − 394
+ − 395
inline PropertyTestClass::TestEnum foo() const { return PropertyTestClass::One; }
+ − 396
};
+ − 397
+ − 398
#if defined(Q_MOC_RUN)
+ − 399
// Task #119503
+ − 400
#define _TASK_119503
+ − 401
#if !_TASK_119503
+ − 402
#endif
+ − 403
#endif
+ − 404
+ − 405
static QString srcify(const char *path)
+ − 406
{
+ − 407
#ifndef Q_OS_IRIX
+ − 408
return QString(SRCDIR) + QLatin1Char('/') + QLatin1String(path);
+ − 409
#else
+ − 410
return QString(QLatin1String(path));
+ − 411
#endif
+ − 412
}
+ − 413
+ − 414
class CtorTestClass : public QObject
+ − 415
{
+ − 416
Q_OBJECT
+ − 417
public:
+ − 418
Q_INVOKABLE CtorTestClass(QObject *parent = 0);
+ − 419
+ − 420
CtorTestClass(int foo);
+ − 421
+ − 422
inline Q_INVOKABLE CtorTestClass(const QString &str)
+ − 423
{ m_str = str; }
+ − 424
+ − 425
QString m_str;
+ − 426
+ − 427
protected:
+ − 428
CtorTestClass(int foo, int bar, int baz);
+ − 429
private:
+ − 430
CtorTestClass(float, float) {}
+ − 431
};
+ − 432
+ − 433
CtorTestClass::CtorTestClass(QObject *parent)
+ − 434
: QObject(parent) {}
+ − 435
+ − 436
CtorTestClass::CtorTestClass(int, int, int) {}
+ − 437
+ − 438
+ − 439
class tst_Moc : public QObject
+ − 440
{
+ − 441
Q_OBJECT
+ − 442
+ − 443
Q_PROPERTY(bool user1 READ user1 USER true )
+ − 444
Q_PROPERTY(bool user2 READ user2 USER false)
+ − 445
Q_PROPERTY(bool user3 READ user3 USER userFunction())
+ − 446
+ − 447
public:
+ − 448
inline tst_Moc() {}
+ − 449
+ − 450
private slots:
+ − 451
void initTestCase();
+ − 452
+ − 453
void slotWithException() throw(MyStruct);
+ − 454
void dontStripNamespaces();
+ − 455
void oldStyleCasts();
+ − 456
void warnOnExtraSignalSlotQualifiaction();
+ − 457
void uLongLong();
+ − 458
void inputFileNameWithDotsButNoExtension();
+ − 459
void userProperties();
+ − 460
void supportConstSignals();
+ − 461
void task87883();
+ − 462
void multilineComments();
+ − 463
void classinfoWithEscapes();
+ − 464
void trNoopInClassInfo();
+ − 465
void ppExpressionEvaluation();
+ − 466
void arrayArguments();
+ − 467
void preprocessorConditionals();
+ − 468
void blackslashNewlines();
+ − 469
void slotWithSillyConst();
+ − 470
void testExtraData();
+ − 471
void namespaceTypeProperty();
+ − 472
void slotsWithVoidTemplate();
+ − 473
void structQObject();
+ − 474
void namespacedFlags();
+ − 475
void warnOnMultipleInheritance();
+ − 476
void forgottenQInterface();
+ − 477
void os9Newline();
+ − 478
void winNewline();
+ − 479
void escapesInStringLiterals();
+ − 480
void frameworkSearchPath();
+ − 481
void cstyleEnums();
+ − 482
void defineMacroViaCmdline();
+ − 483
void invokable();
+ − 484
void singleFunctionKeywordSignalAndSlot();
+ − 485
void templateGtGt();
+ − 486
void qprivateslots();
+ − 487
void inlineSlotsWithThrowDeclaration();
+ − 488
void warnOnPropertyWithoutREAD();
+ − 489
void constructors();
+ − 490
void typenameWithUnsigned();
+ − 491
void warnOnVirtualSignal();
3
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 492
void QTBUG5590_dummyProperty();
0
+ − 493
signals:
+ − 494
void sigWithUnsignedArg(unsigned foo);
+ − 495
void sigWithSignedArg(signed foo);
+ − 496
void sigWithConstSignedArg(const signed foo);
+ − 497
void sigWithVolatileConstSignedArg(volatile const signed foo);
+ − 498
void sigWithCustomType(const MyStruct);
+ − 499
void constSignal1() const;
+ − 500
void constSignal2(int arg) const;
+ − 501
+ − 502
private:
+ − 503
bool user1() { return true; };
+ − 504
bool user2() { return false; };
+ − 505
bool user3() { return false; };
+ − 506
bool userFunction(){ return false; };
+ − 507
+ − 508
private:
+ − 509
QString qtIncludePath;
+ − 510
};
+ − 511
+ − 512
void tst_Moc::initTestCase()
+ − 513
{
+ − 514
#if defined(Q_OS_UNIX) && !defined(QT_NO_PROCESS)
+ − 515
QProcess proc;
+ − 516
proc.start("qmake", QStringList() << "-query" << "QT_INSTALL_HEADERS");
+ − 517
QVERIFY(proc.waitForFinished());
+ − 518
QCOMPARE(proc.exitCode(), 0);
+ − 519
QByteArray output = proc.readAllStandardOutput();
+ − 520
QVERIFY(!output.isEmpty());
+ − 521
QCOMPARE(proc.readAllStandardError(), QByteArray());
+ − 522
qtIncludePath = QString::fromLocal8Bit(output).trimmed();
+ − 523
QFileInfo fi(qtIncludePath);
+ − 524
QVERIFY(fi.exists());
+ − 525
QVERIFY(fi.isDir());
+ − 526
#endif
+ − 527
}
+ − 528
+ − 529
void tst_Moc::slotWithException() throw(MyStruct)
+ − 530
{
+ − 531
// be happy
+ − 532
QVERIFY(true);
+ − 533
}
+ − 534
+ − 535
void tst_Moc::dontStripNamespaces()
+ − 536
{
+ − 537
Sender sender;
+ − 538
Receiver receiver;
+ − 539
+ − 540
connect(&sender, SIGNAL(send(const String::Type &)),
+ − 541
&receiver, SLOT(receive(const String::Type &)));
+ − 542
connect(&sender, SIGNAL(send(const Int::Type &)),
+ − 543
&receiver, SLOT(receive(const Int::Type &)));
+ − 544
+ − 545
sender.sendValue(String::Type("Hello"));
+ − 546
QCOMPARE(receiver.stringCallCount, 1);
+ − 547
QCOMPARE(receiver.intCallCount, 0);
+ − 548
sender.sendValue(Int::Type(42));
+ − 549
QCOMPARE(receiver.stringCallCount, 1);
+ − 550
QCOMPARE(receiver.intCallCount, 1);
+ − 551
}
+ − 552
+ − 553
+ − 554
void tst_Moc::oldStyleCasts()
+ − 555
{
+ − 556
#ifdef MOC_CROSS_COMPILED
+ − 557
QSKIP("Not tested when cross-compiled", SkipAll);
+ − 558
#endif
+ − 559
#if defined(Q_OS_LINUX) && defined(Q_CC_GNU) && !defined(QT_NO_PROCESS)
+ − 560
QProcess proc;
+ − 561
proc.start("moc", QStringList(srcify("/oldstyle-casts.h")));
+ − 562
QVERIFY(proc.waitForFinished());
+ − 563
QCOMPARE(proc.exitCode(), 0);
+ − 564
QByteArray mocOut = proc.readAllStandardOutput();
+ − 565
QVERIFY(!mocOut.isEmpty());
+ − 566
QCOMPARE(proc.readAllStandardError(), QByteArray());
+ − 567
+ − 568
QStringList args;
+ − 569
args << "-c" << "-x" << "c++" << "-Wold-style-cast" << "-I" << "."
+ − 570
<< "-I" << qtIncludePath << "-o" << "/dev/null" << "-";
+ − 571
proc.start("gcc", args);
+ − 572
QVERIFY(proc.waitForStarted());
+ − 573
proc.write(mocOut);
+ − 574
proc.closeWriteChannel();
+ − 575
+ − 576
QVERIFY(proc.waitForFinished());
+ − 577
QCOMPARE(proc.exitCode(), 0);
+ − 578
QCOMPARE(QString::fromLocal8Bit(proc.readAllStandardError()), QString());
+ − 579
#else
+ − 580
QSKIP("Only tested on linux/gcc", SkipAll);
+ − 581
#endif
+ − 582
}
+ − 583
+ − 584
void tst_Moc::warnOnExtraSignalSlotQualifiaction()
+ − 585
{
+ − 586
#ifdef MOC_CROSS_COMPILED
+ − 587
QSKIP("Not tested when cross-compiled", SkipAll);
+ − 588
#endif
+ − 589
#if defined(Q_OS_LINUX) && defined(Q_CC_GNU) && !defined(QT_NO_PROCESS)
+ − 590
QProcess proc;
+ − 591
proc.start("moc", QStringList(srcify("extraqualification.h")));
+ − 592
QVERIFY(proc.waitForFinished());
+ − 593
QCOMPARE(proc.exitCode(), 0);
+ − 594
QByteArray mocOut = proc.readAllStandardOutput();
+ − 595
QVERIFY(!mocOut.isEmpty());
+ − 596
QString mocWarning = QString::fromLocal8Bit(proc.readAllStandardError());
+ − 597
QCOMPARE(mocWarning, QString(SRCDIR) +
+ − 598
QString("/extraqualification.h:53: Warning: Function declaration Test::badFunctionDeclaration contains extra qualification. Ignoring as signal or slot.\n") +
+ − 599
QString(SRCDIR) + QString("/extraqualification.h:56: Warning: parsemaybe: Function declaration Test::anotherOne contains extra qualification. Ignoring as signal or slot.\n"));
+ − 600
#else
+ − 601
QSKIP("Only tested on linux/gcc", SkipAll);
+ − 602
#endif
+ − 603
}
+ − 604
+ − 605
void tst_Moc::uLongLong()
+ − 606
{
+ − 607
#ifndef NOLONGLONG
+ − 608
TestClass tst;
+ − 609
const QMetaObject *mobj = tst.metaObject();
+ − 610
int idx = mobj->indexOfSlot("slotWithULong(ulong)");
+ − 611
QVERIFY(idx != -1);
+ − 612
idx = mobj->indexOfSlot("slotWithULongLong(unsigned long long)");
+ − 613
QVERIFY(idx != -1);
+ − 614
idx = mobj->indexOfSlot("slotWithULongLongP(unsigned long long*)");
+ − 615
QVERIFY(idx != -1);
+ − 616
+ − 617
idx = mobj->indexOfSlot("slotWithLong(long)");
+ − 618
QVERIFY(idx != -1);
+ − 619
idx = mobj->indexOfSlot("slotWithLongLong(long long)");
+ − 620
QVERIFY(idx != -1);
+ − 621
#else
+ − 622
QSKIP("long long doesn't work on MSVC6 & .NET 2002, also skipped on 2003 due to compiler version issue with moc", SkipAll);
+ − 623
#endif
+ − 624
}
+ − 625
+ − 626
void tst_Moc::inputFileNameWithDotsButNoExtension()
+ − 627
{
+ − 628
#ifdef MOC_CROSS_COMPILED
+ − 629
QSKIP("Not tested when cross-compiled", SkipAll);
+ − 630
#endif
+ − 631
#if defined(Q_OS_LINUX) && defined(Q_CC_GNU) && !defined(QT_NO_PROCESS)
+ − 632
QProcess proc;
+ − 633
proc.setWorkingDirectory(QString(SRCDIR) + "/task71021");
+ − 634
proc.start("moc", QStringList("../Header"));
+ − 635
QVERIFY(proc.waitForFinished());
+ − 636
QCOMPARE(proc.exitCode(), 0);
+ − 637
QByteArray mocOut = proc.readAllStandardOutput();
+ − 638
QVERIFY(!mocOut.isEmpty());
+ − 639
QCOMPARE(proc.readAllStandardError(), QByteArray());
+ − 640
+ − 641
QStringList args;
+ − 642
args << "-c" << "-x" << "c++" << "-I" << ".."
+ − 643
<< "-I" << qtIncludePath << "-o" << "/dev/null" << "-";
+ − 644
proc.start("gcc", args);
+ − 645
QVERIFY(proc.waitForStarted());
+ − 646
proc.write(mocOut);
+ − 647
proc.closeWriteChannel();
+ − 648
+ − 649
QVERIFY(proc.waitForFinished());
+ − 650
QCOMPARE(QString::fromLocal8Bit(proc.readAllStandardError()), QString());
+ − 651
QCOMPARE(proc.exitCode(), 0);
+ − 652
#else
+ − 653
QSKIP("Only tested on linux/gcc", SkipAll);
+ − 654
#endif
+ − 655
}
+ − 656
+ − 657
void tst_Moc::userProperties()
+ − 658
{
+ − 659
const QMetaObject *mobj = metaObject();
+ − 660
QMetaProperty property = mobj->property(mobj->indexOfProperty("user1"));
+ − 661
QVERIFY(property.isValid());
+ − 662
QVERIFY(property.isUser());
+ − 663
+ − 664
property = mobj->property(mobj->indexOfProperty("user2"));
+ − 665
QVERIFY(property.isValid());
+ − 666
QVERIFY(!property.isUser());
+ − 667
+ − 668
property = mobj->property(mobj->indexOfProperty("user3"));
+ − 669
QVERIFY(property.isValid());
+ − 670
QVERIFY(!property.isUser(this));
+ − 671
}
+ − 672
+ − 673
void tst_Moc::supportConstSignals()
+ − 674
{
+ − 675
QSignalSpy spy1(this, SIGNAL(constSignal1()));
+ − 676
QVERIFY(spy1.isEmpty());
+ − 677
emit constSignal1();
+ − 678
QCOMPARE(spy1.count(), 1);
+ − 679
+ − 680
QSignalSpy spy2(this, SIGNAL(constSignal2(int)));
+ − 681
QVERIFY(spy2.isEmpty());
+ − 682
emit constSignal2(42);
+ − 683
QCOMPARE(spy2.count(), 1);
+ − 684
QCOMPARE(spy2.at(0).at(0).toInt(), 42);
+ − 685
}
+ − 686
+ − 687
#include "task87883.h"
+ − 688
+ − 689
void tst_Moc::task87883()
+ − 690
{
+ − 691
QVERIFY(Task87883::staticMetaObject.className());
+ − 692
}
+ − 693
+ − 694
#include "c-comments.h"
+ − 695
+ − 696
void tst_Moc::multilineComments()
+ − 697
{
+ − 698
QVERIFY(IfdefedClass::staticMetaObject.className());
+ − 699
}
+ − 700
+ − 701
void tst_Moc::classinfoWithEscapes()
+ − 702
{
+ − 703
const QMetaObject *mobj = &TestClassinfoWithEscapes::staticMetaObject;
+ − 704
QCOMPARE(mobj->methodCount() - mobj->methodOffset(), 1);
+ − 705
+ − 706
QMetaMethod mm = mobj->method(mobj->methodOffset());
+ − 707
QCOMPARE(mm.signature(), "slotWithAReallyLongName(int)");
+ − 708
}
+ − 709
+ − 710
void tst_Moc::trNoopInClassInfo()
+ − 711
{
+ − 712
TestClass t;
+ − 713
const QMetaObject *mobj = t.metaObject();
+ − 714
QVERIFY(mobj);
+ − 715
QCOMPARE(mobj->classInfoCount(), 3);
+ − 716
QCOMPARE(mobj->indexOfClassInfo("help"), 0);
+ − 717
QCOMPARE(QString(mobj->classInfo(0).value()), QString("Opening this will let you configure something"));
+ − 718
}
+ − 719
+ − 720
void tst_Moc::ppExpressionEvaluation()
+ − 721
{
+ − 722
TestClass tst;
+ − 723
const QMetaObject *mobj = tst.metaObject();
+ − 724
int idx = mobj->indexOfSlot("expressionEvaluationShortcut1()");
+ − 725
QVERIFY(idx != -1);
+ − 726
+ − 727
idx = mobj->indexOfSlot("expressionEvaluationShortcut2()");
+ − 728
QVERIFY(idx != -1);
+ − 729
}
+ − 730
+ − 731
void tst_Moc::arrayArguments()
+ − 732
{
+ − 733
TestClass tst;
+ − 734
const QMetaObject *mobj = tst.metaObject();
+ − 735
QVERIFY(mobj->indexOfSlot("slotWithArray(const double[3])") != -1);
+ − 736
QVERIFY(mobj->indexOfSlot("slotWithNamedArray(const double[3])") != -1);
+ − 737
QVERIFY(mobj->indexOfSlot("slotWithMultiArray(const double[3][4])") != -1);
+ − 738
QVERIFY(mobj->indexOfSignal("signalWithArray(const double[3])") != -1);
+ − 739
QVERIFY(mobj->indexOfSignal("signalWithNamedArray(const double[3])") != -1);
+ − 740
}
+ − 741
+ − 742
void tst_Moc::preprocessorConditionals()
+ − 743
{
+ − 744
TestClass tst;
+ − 745
const QMetaObject *mobj = tst.metaObject();
+ − 746
QVERIFY(mobj->indexOfSlot("slotInElse()") != -1);
+ − 747
QVERIFY(mobj->indexOfSlot("slotInIf()") != -1);
+ − 748
QVERIFY(mobj->indexOfSlot("slotInLastElse()") != -1);
+ − 749
QVERIFY(mobj->indexOfSlot("slotInElif()") != -1);
+ − 750
}
+ − 751
+ − 752
void tst_Moc::blackslashNewlines()
+ − 753
{
+ − 754
BackslashNewlines tst;
+ − 755
const QMetaObject *mobj = tst.metaObject();
+ − 756
QVERIFY(mobj->indexOfSlot("works()") != -1);
+ − 757
QVERIFY(mobj->indexOfSlot("buggy()") == -1);
+ − 758
}
+ − 759
+ − 760
void tst_Moc::slotWithSillyConst()
+ − 761
{
+ − 762
TestClass tst;
+ − 763
const QMetaObject *mobj = tst.metaObject();
+ − 764
QVERIFY(mobj->indexOfSlot("slotWithSillyConst()") != -1);
+ − 765
QVERIFY(mobj->indexOfMethod("slotWithSillyConst2()") != -1);
+ − 766
QVERIFY(mobj->indexOfSlot("slotWithVoidStar(void*)") != -1);
+ − 767
}
+ − 768
+ − 769
void tst_Moc::testExtraData()
+ − 770
{
+ − 771
const QMetaObject *mobj = &PropertyTestClass::staticMetaObject;
+ − 772
QCOMPARE(mobj->enumeratorCount(), 1);
+ − 773
QCOMPARE(QByteArray(mobj->enumerator(0).name()), QByteArray("TestEnum"));
+ − 774
+ − 775
mobj = &PropertyUseClass::staticMetaObject;
+ − 776
const int idx = mobj->indexOfProperty("foo");
+ − 777
QVERIFY(idx != -1);
+ − 778
const QMetaProperty prop = mobj->property(idx);
+ − 779
QVERIFY(prop.isValid());
+ − 780
QVERIFY(prop.isEnumType());
+ − 781
const QMetaEnum en = prop.enumerator();
+ − 782
QCOMPARE(QByteArray(en.name()), QByteArray("TestEnum"));
+ − 783
}
+ − 784
+ − 785
void tst_Moc::namespaceTypeProperty()
+ − 786
{
+ − 787
qRegisterMetaType<myNS::Points>("myNS::Points");
+ − 788
TestClass tst;
+ − 789
QByteArray ba = QByteArray("points");
+ − 790
QVariant v = tst.property(ba);
+ − 791
QVERIFY(v.isValid());
+ − 792
myNS::Points p = qVariantValue<myNS::Points>(v);
+ − 793
QCOMPARE(p.p1, 0xBEEF);
+ − 794
QCOMPARE(p.p2, 0xBABE);
+ − 795
p.p1 = 0xCAFE;
+ − 796
p.p2 = 0x1EE7;
+ − 797
QVERIFY(tst.setProperty(ba, qVariantFromValue(p)));
+ − 798
myNS::Points pp = qVariantValue<myNS::Points>(tst.property(ba));
+ − 799
QCOMPARE(p.p1, pp.p1);
+ − 800
QCOMPARE(p.p2, pp.p2);
+ − 801
}
+ − 802
+ − 803
void tst_Moc::slotsWithVoidTemplate()
+ − 804
{
+ − 805
SlotsWithVoidTemplateTest test;
+ − 806
QVERIFY(QObject::connect(&test, SIGNAL(myVoidSignal(void)),
+ − 807
&test, SLOT(dummySlot(void))));
+ − 808
QVERIFY(QObject::connect(&test, SIGNAL(mySignal(const TestTemplate<void> &)),
+ − 809
&test, SLOT(anotherSlot(const TestTemplate<void> &))));
+ − 810
}
+ − 811
+ − 812
void tst_Moc::structQObject()
+ − 813
{
+ − 814
StructQObject o;
+ − 815
QCOMPARE(QByteArray(o.metaObject()->className()), QByteArray("StructQObject"));
+ − 816
}
+ − 817
+ − 818
#include "namespaced-flags.h"
+ − 819
3
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 820
Q_DECLARE_METATYPE(QList<Foo::Bar::Flags>);
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 821
0
+ − 822
void tst_Moc::namespacedFlags()
+ − 823
{
+ − 824
Foo::Baz baz;
+ − 825
Foo::Bar bar;
+ − 826
+ − 827
bar.setFlags(Foo::Bar::Read | Foo::Bar::Write);
+ − 828
QVERIFY(baz.flags() != bar.flags());
+ − 829
+ − 830
const QVariant v = bar.property("flags");
+ − 831
QVERIFY(v.isValid());
+ − 832
QVERIFY(baz.setProperty("flags", v));
+ − 833
QVERIFY(baz.flags() == bar.flags());
3
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 834
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 835
QList<Foo::Bar::Flags> l;
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 836
l << baz.flags();
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 837
QVariant v2 = baz.setProperty("flagsList", QVariant::fromValue(l));
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 838
QCOMPARE(l, baz.flagsList());
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 839
QCOMPARE(l, qvariant_cast<QList<Foo::Bar::Flags> >(baz.property("flagsList")));
0
+ − 840
}
+ − 841
+ − 842
void tst_Moc::warnOnMultipleInheritance()
+ − 843
{
+ − 844
#ifdef MOC_CROSS_COMPILED
+ − 845
QSKIP("Not tested when cross-compiled", SkipAll);
+ − 846
#endif
+ − 847
#if defined(Q_OS_LINUX) && defined(Q_CC_GNU) && !defined(QT_NO_PROCESS)
+ − 848
QProcess proc;
+ − 849
QStringList args;
+ − 850
args << "-I" << qtIncludePath + "/QtGui"
+ − 851
<< srcify("warn-on-multiple-qobject-subclasses.h");
+ − 852
proc.start("moc", args);
+ − 853
QVERIFY(proc.waitForFinished());
+ − 854
QCOMPARE(proc.exitCode(), 0);
+ − 855
QByteArray mocOut = proc.readAllStandardOutput();
+ − 856
QVERIFY(!mocOut.isEmpty());
+ − 857
QString mocWarning = QString::fromLocal8Bit(proc.readAllStandardError());
+ − 858
QCOMPARE(mocWarning, QString(SRCDIR) +
+ − 859
QString("/warn-on-multiple-qobject-subclasses.h:53: Warning: Class Bar inherits from two QObject subclasses QWidget and Foo. This is not supported!\n"));
+ − 860
#else
+ − 861
QSKIP("Only tested on linux/gcc", SkipAll);
+ − 862
#endif
+ − 863
}
+ − 864
+ − 865
void tst_Moc::forgottenQInterface()
+ − 866
{
+ − 867
#ifdef MOC_CROSS_COMPILED
+ − 868
QSKIP("Not tested when cross-compiled", SkipAll);
+ − 869
#endif
+ − 870
#if defined(Q_OS_LINUX) && defined(Q_CC_GNU) && !defined(QT_NO_PROCESS)
+ − 871
QProcess proc;
+ − 872
QStringList args;
+ − 873
args << "-I" << qtIncludePath + "/QtCore"
+ − 874
<< srcify("forgotten-qinterface.h");
+ − 875
proc.start("moc", args);
+ − 876
QVERIFY(proc.waitForFinished());
+ − 877
QCOMPARE(proc.exitCode(), 0);
+ − 878
QByteArray mocOut = proc.readAllStandardOutput();
+ − 879
QVERIFY(!mocOut.isEmpty());
+ − 880
QString mocWarning = QString::fromLocal8Bit(proc.readAllStandardError());
+ − 881
QCOMPARE(mocWarning, QString(SRCDIR) +
+ − 882
QString("/forgotten-qinterface.h:55: Warning: Class Test implements the interface MyInterface but does not list it in Q_INTERFACES. qobject_cast to MyInterface will not work!\n"));
+ − 883
#else
+ − 884
QSKIP("Only tested on linux/gcc", SkipAll);
+ − 885
#endif
+ − 886
}
+ − 887
+ − 888
void tst_Moc::os9Newline()
+ − 889
{
+ − 890
#if !defined(SKIP_NEWLINE_TEST)
+ − 891
const QMetaObject &mo = Os9Newlines::staticMetaObject;
+ − 892
QVERIFY(mo.indexOfSlot("testSlot()") != -1);
+ − 893
QFile f(srcify("os9-newlines.h"));
+ − 894
QVERIFY(f.open(QIODevice::ReadOnly)); // no QIODevice::Text!
+ − 895
QByteArray data = f.readAll();
+ − 896
f.close();
+ − 897
QVERIFY(!data.contains('\n'));
+ − 898
QVERIFY(data.contains('\r'));
+ − 899
#endif
+ − 900
}
+ − 901
+ − 902
void tst_Moc::winNewline()
+ − 903
{
+ − 904
#if !defined(SKIP_NEWLINE_TEST)
+ − 905
const QMetaObject &mo = WinNewlines::staticMetaObject;
+ − 906
QVERIFY(mo.indexOfSlot("testSlot()") != -1);
+ − 907
QFile f(srcify("win-newlines.h"));
+ − 908
QVERIFY(f.open(QIODevice::ReadOnly)); // no QIODevice::Text!
+ − 909
QByteArray data = f.readAll();
+ − 910
f.close();
+ − 911
for (int i = 0; i < data.count(); ++i) {
+ − 912
if (data.at(i) == QLatin1Char('\r')) {
+ − 913
QVERIFY(i < data.count() - 1);
+ − 914
++i;
+ − 915
QVERIFY(data.at(i) == '\n');
+ − 916
} else {
+ − 917
QVERIFY(data.at(i) != '\n');
+ − 918
}
+ − 919
}
+ − 920
#endif
+ − 921
}
+ − 922
+ − 923
void tst_Moc::escapesInStringLiterals()
+ − 924
{
+ − 925
const QMetaObject &mo = StringLiterals::staticMetaObject;
+ − 926
QCOMPARE(mo.classInfoCount(), 3);
+ − 927
+ − 928
int idx = mo.indexOfClassInfo("Test");
+ − 929
QVERIFY(idx != -1);
+ − 930
QMetaClassInfo info = mo.classInfo(idx);
+ − 931
QCOMPARE(QByteArray(info.value()),
+ − 932
QByteArray("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\x53"));
+ − 933
+ − 934
QVERIFY(idx != -1);
+ − 935
idx = mo.indexOfClassInfo("Test2");
+ − 936
info = mo.classInfo(idx);
+ − 937
QCOMPARE(QByteArray(info.value()),
+ − 938
QByteArray("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\123"));
+ − 939
+ − 940
QVERIFY(idx != -1);
+ − 941
idx = mo.indexOfClassInfo("Test3");
+ − 942
info = mo.classInfo(idx);
+ − 943
QCOMPARE(QByteArray(info.value()),
+ − 944
QByteArray("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nb"));
+ − 945
}
+ − 946
+ − 947
void tst_Moc::frameworkSearchPath()
+ − 948
{
+ − 949
#ifdef MOC_CROSS_COMPILED
+ − 950
QSKIP("Not tested when cross-compiled", SkipAll);
+ − 951
#endif
+ − 952
#if defined(Q_OS_UNIX) && !defined(QT_NO_PROCESS)
+ − 953
QStringList args;
+ − 954
args << "-F" << srcify(".")
+ − 955
<< srcify("interface-from-framework.h")
+ − 956
;
+ − 957
+ − 958
QProcess proc;
+ − 959
proc.start("moc", args);
+ − 960
bool finished = proc.waitForFinished();
+ − 961
if (!finished)
+ − 962
qWarning("waitForFinished failed. QProcess error: %d", (int)proc.error());
+ − 963
QVERIFY(finished);
+ − 964
if (proc.exitCode() != 0) {
+ − 965
qDebug() << proc.readAllStandardError();
+ − 966
}
+ − 967
QCOMPARE(proc.exitCode(), 0);
+ − 968
QCOMPARE(proc.readAllStandardError(), QByteArray());
+ − 969
#else
+ − 970
QSKIP("Only tested/relevant on unixy platforms", SkipAll);
+ − 971
#endif
+ − 972
}
+ − 973
+ − 974
void tst_Moc::cstyleEnums()
+ − 975
{
+ − 976
const QMetaObject &obj = CStyleEnums::staticMetaObject;
+ − 977
QCOMPARE(obj.enumeratorCount(), 1);
+ − 978
QMetaEnum metaEnum = obj.enumerator(0);
+ − 979
QCOMPARE(metaEnum.name(), "Baz");
+ − 980
QCOMPARE(metaEnum.keyCount(), 2);
+ − 981
QCOMPARE(metaEnum.key(0), "Foo");
+ − 982
QCOMPARE(metaEnum.key(1), "Bar");
+ − 983
}
+ − 984
+ − 985
void tst_Moc::templateGtGt()
+ − 986
{
+ − 987
#ifdef MOC_CROSS_COMPILED
+ − 988
QSKIP("Not tested when cross-compiled", SkipAll);
+ − 989
#endif
+ − 990
#if defined(Q_OS_LINUX) && defined(Q_CC_GNU) && !defined(QT_NO_PROCESS)
+ − 991
QProcess proc;
+ − 992
proc.start("moc", QStringList(srcify("template-gtgt.h")));
+ − 993
QVERIFY(proc.waitForFinished());
+ − 994
QCOMPARE(proc.exitCode(), 0);
+ − 995
QByteArray mocOut = proc.readAllStandardOutput();
+ − 996
QVERIFY(!mocOut.isEmpty());
+ − 997
QString mocWarning = QString::fromLocal8Bit(proc.readAllStandardError());
+ − 998
QVERIFY(mocWarning.isEmpty());
+ − 999
#else
+ − 1000
QSKIP("Only tested on linux/gcc", SkipAll);
+ − 1001
#endif
+ − 1002
}
+ − 1003
+ − 1004
void tst_Moc::defineMacroViaCmdline()
+ − 1005
{
+ − 1006
#if defined(Q_OS_LINUX) && defined(Q_CC_GNU) && !defined(QT_NO_PROCESS)
+ − 1007
QProcess proc;
+ − 1008
+ − 1009
QStringList args;
+ − 1010
args << "-DFOO";
+ − 1011
args << srcify("macro-on-cmdline.h");
+ − 1012
+ − 1013
proc.start("moc", args);
+ − 1014
QVERIFY(proc.waitForFinished());
+ − 1015
QCOMPARE(proc.exitCode(), 0);
+ − 1016
QCOMPARE(proc.readAllStandardError(), QByteArray());
+ − 1017
QByteArray mocOut = proc.readAllStandardOutput();
+ − 1018
QVERIFY(!mocOut.isEmpty());
+ − 1019
#else
+ − 1020
QSKIP("Only tested on linux/gcc", SkipAll);
+ − 1021
#endif
+ − 1022
}
+ − 1023
+ − 1024
void tst_Moc::invokable()
+ − 1025
{
+ − 1026
{
+ − 1027
const QMetaObject &mobj = InvokableBeforeReturnType::staticMetaObject;
+ − 1028
QCOMPARE(mobj.methodCount(), 5);
+ − 1029
QVERIFY(mobj.method(4).signature() == QByteArray("foo()"));
+ − 1030
}
+ − 1031
+ − 1032
{
+ − 1033
const QMetaObject &mobj = InvokableBeforeInline::staticMetaObject;
+ − 1034
QCOMPARE(mobj.methodCount(), 6);
+ − 1035
QVERIFY(mobj.method(4).signature() == QByteArray("foo()"));
+ − 1036
QVERIFY(mobj.method(5).signature() == QByteArray("bar()"));
+ − 1037
}
+ − 1038
}
+ − 1039
+ − 1040
void tst_Moc::singleFunctionKeywordSignalAndSlot()
+ − 1041
{
+ − 1042
{
+ − 1043
const QMetaObject &mobj = SingleFunctionKeywordBeforeReturnType::staticMetaObject;
+ − 1044
QCOMPARE(mobj.methodCount(), 6);
+ − 1045
QVERIFY(mobj.method(4).signature() == QByteArray("mySignal()"));
+ − 1046
QVERIFY(mobj.method(5).signature() == QByteArray("mySlot()"));
+ − 1047
}
+ − 1048
+ − 1049
{
+ − 1050
const QMetaObject &mobj = SingleFunctionKeywordBeforeInline::staticMetaObject;
+ − 1051
QCOMPARE(mobj.methodCount(), 6);
+ − 1052
QVERIFY(mobj.method(4).signature() == QByteArray("mySignal()"));
+ − 1053
QVERIFY(mobj.method(5).signature() == QByteArray("mySlot()"));
+ − 1054
}
+ − 1055
+ − 1056
{
+ − 1057
const QMetaObject &mobj = SingleFunctionKeywordAfterInline::staticMetaObject;
+ − 1058
QCOMPARE(mobj.methodCount(), 6);
+ − 1059
QVERIFY(mobj.method(4).signature() == QByteArray("mySignal()"));
+ − 1060
QVERIFY(mobj.method(5).signature() == QByteArray("mySlot()"));
+ − 1061
}
+ − 1062
}
+ − 1063
+ − 1064
#include "qprivateslots.h"
+ − 1065
+ − 1066
void tst_Moc::qprivateslots()
+ − 1067
{
+ − 1068
TestQPrivateSlots tst;
+ − 1069
const QMetaObject *mobj = tst.metaObject();
+ − 1070
QVERIFY(mobj->indexOfSlot("_q_privateslot()") != -1);
+ − 1071
QVERIFY(mobj->indexOfMethod("method1()") != -1); //tast204730
+ − 1072
}
+ − 1073
+ − 1074
#include "task189996.h"
+ − 1075
+ − 1076
void InlineSlotsWithThrowDeclaration::c() throw() {}
+ − 1077
+ − 1078
void tst_Moc::inlineSlotsWithThrowDeclaration()
+ − 1079
{
+ − 1080
InlineSlotsWithThrowDeclaration tst;
+ − 1081
const QMetaObject *mobj = tst.metaObject();
+ − 1082
QVERIFY(mobj->indexOfSlot("a()") != -1);
+ − 1083
QVERIFY(mobj->indexOfSlot("b()") != -1);
+ − 1084
QVERIFY(mobj->indexOfSlot("c()") != -1);
+ − 1085
QVERIFY(mobj->indexOfSlot("d()") != -1);
+ − 1086
QVERIFY(mobj->indexOfSlot("e()") != -1);
+ − 1087
}
+ − 1088
+ − 1089
void tst_Moc::warnOnPropertyWithoutREAD()
+ − 1090
{
+ − 1091
#ifdef MOC_CROSS_COMPILED
+ − 1092
QSKIP("Not tested when cross-compiled", SkipAll);
+ − 1093
#endif
+ − 1094
#if defined(Q_OS_LINUX) && defined(Q_CC_GNU) && !defined(QT_NO_PROCESS)
+ − 1095
QProcess proc;
+ − 1096
proc.start("moc", QStringList(srcify("warn-on-property-without-read.h")));
+ − 1097
QVERIFY(proc.waitForFinished());
+ − 1098
QCOMPARE(proc.exitCode(), 0);
+ − 1099
QByteArray mocOut = proc.readAllStandardOutput();
+ − 1100
QVERIFY(!mocOut.isEmpty());
+ − 1101
QString mocWarning = QString::fromLocal8Bit(proc.readAllStandardError());
+ − 1102
QCOMPARE(mocWarning, QString(SRCDIR) +
+ − 1103
QString("/warn-on-property-without-read.h:46: Warning: Property declaration foo has no READ accessor function. The property will be invalid.\n"));
+ − 1104
#else
+ − 1105
QSKIP("Only tested on linux/gcc", SkipAll);
+ − 1106
#endif
+ − 1107
}
+ − 1108
+ − 1109
void tst_Moc::constructors()
+ − 1110
{
+ − 1111
const QMetaObject *mo = &CtorTestClass::staticMetaObject;
+ − 1112
QCOMPARE(mo->constructorCount(), 3);
+ − 1113
{
+ − 1114
QMetaMethod mm = mo->constructor(0);
+ − 1115
QCOMPARE(mm.access(), QMetaMethod::Public);
+ − 1116
QCOMPARE(mm.methodType(), QMetaMethod::Constructor);
+ − 1117
QCOMPARE(mm.signature(), "CtorTestClass(QObject*)");
+ − 1118
QCOMPARE(mm.typeName(), "");
+ − 1119
QList<QByteArray> paramNames = mm.parameterNames();
+ − 1120
QCOMPARE(paramNames.size(), 1);
+ − 1121
QCOMPARE(paramNames.at(0), QByteArray("parent"));
+ − 1122
QList<QByteArray> paramTypes = mm.parameterTypes();
+ − 1123
QCOMPARE(paramTypes.size(), 1);
+ − 1124
QCOMPARE(paramTypes.at(0), QByteArray("QObject*"));
+ − 1125
}
+ − 1126
{
+ − 1127
QMetaMethod mm = mo->constructor(1);
+ − 1128
QCOMPARE(mm.access(), QMetaMethod::Public);
+ − 1129
QCOMPARE(mm.methodType(), QMetaMethod::Constructor);
+ − 1130
QCOMPARE(mm.signature(), "CtorTestClass()");
+ − 1131
QCOMPARE(mm.typeName(), "");
+ − 1132
QCOMPARE(mm.parameterNames().size(), 0);
+ − 1133
QCOMPARE(mm.parameterTypes().size(), 0);
+ − 1134
}
+ − 1135
{
+ − 1136
QMetaMethod mm = mo->constructor(2);
+ − 1137
QCOMPARE(mm.access(), QMetaMethod::Public);
+ − 1138
QCOMPARE(mm.methodType(), QMetaMethod::Constructor);
+ − 1139
QCOMPARE(mm.signature(), "CtorTestClass(QString)");
+ − 1140
QCOMPARE(mm.typeName(), "");
+ − 1141
QList<QByteArray> paramNames = mm.parameterNames();
+ − 1142
QCOMPARE(paramNames.size(), 1);
+ − 1143
QCOMPARE(paramNames.at(0), QByteArray("str"));
+ − 1144
QList<QByteArray> paramTypes = mm.parameterTypes();
+ − 1145
QCOMPARE(paramTypes.size(), 1);
+ − 1146
QCOMPARE(paramTypes.at(0), QByteArray("QString"));
+ − 1147
}
+ − 1148
+ − 1149
QCOMPARE(mo->indexOfConstructor("CtorTestClass(QObject*)"), 0);
+ − 1150
QCOMPARE(mo->indexOfConstructor("CtorTestClass()"), 1);
+ − 1151
QCOMPARE(mo->indexOfConstructor("CtorTestClass(QString)"), 2);
+ − 1152
QCOMPARE(mo->indexOfConstructor("CtorTestClass2(QObject*)"), -1);
+ − 1153
QCOMPARE(mo->indexOfConstructor("CtorTestClass(float,float)"), -1);
+ − 1154
+ − 1155
QObject *o1 = mo->newInstance();
+ − 1156
QVERIFY(o1 != 0);
+ − 1157
QCOMPARE(o1->parent(), (QObject*)0);
+ − 1158
QVERIFY(qobject_cast<CtorTestClass*>(o1) != 0);
+ − 1159
+ − 1160
QObject *o2 = mo->newInstance(Q_ARG(QObject*, o1));
+ − 1161
QVERIFY(o2 != 0);
+ − 1162
QCOMPARE(o2->parent(), o1);
+ − 1163
+ − 1164
QString str = QString::fromLatin1("hello");
+ − 1165
QObject *o3 = mo->newInstance(Q_ARG(QString, str));
+ − 1166
QVERIFY(o3 != 0);
+ − 1167
QCOMPARE(qobject_cast<CtorTestClass*>(o3)->m_str, str);
+ − 1168
+ − 1169
{
+ − 1170
//explicit constructor
+ − 1171
QObject *o = QObject::staticMetaObject.newInstance();
+ − 1172
QVERIFY(o);
+ − 1173
delete o;
+ − 1174
}
+ − 1175
}
+ − 1176
+ − 1177
#include "task234909.h"
+ − 1178
+ − 1179
#include "task240368.h"
+ − 1180
+ − 1181
void tst_Moc::typenameWithUnsigned()
+ − 1182
{
+ − 1183
TypenameWithUnsigned tst;
+ − 1184
const QMetaObject *mobj = tst.metaObject();
+ − 1185
QVERIFY(mobj->indexOfSlot("a(uint)") != -1);
+ − 1186
QVERIFY(mobj->indexOfSlot("b(uint)") != -1);
+ − 1187
QVERIFY(mobj->indexOfSlot("c(uint*)") != -1);
+ − 1188
QVERIFY(mobj->indexOfSlot("d(uint*)") != -1);
+ − 1189
QVERIFY(mobj->indexOfSlot("e(uint&)") != -1);
+ − 1190
QVERIFY(mobj->indexOfSlot("f(uint&)") != -1);
+ − 1191
QVERIFY(mobj->indexOfSlot("g(unsigned1)") != -1);
+ − 1192
QVERIFY(mobj->indexOfSlot("h(unsigned1)") != -1);
+ − 1193
QVERIFY(mobj->indexOfSlot("i(uint,unsigned1)") != -1);
+ − 1194
QVERIFY(mobj->indexOfSlot("j(unsigned1,uint)") != -1);
+ − 1195
QVERIFY(mobj->indexOfSlot("k(unsignedQImage)") != -1);
+ − 1196
QVERIFY(mobj->indexOfSlot("l(unsignedQImage)") != -1);
+ − 1197
}
+ − 1198
+ − 1199
+ − 1200
void tst_Moc::warnOnVirtualSignal()
+ − 1201
{
+ − 1202
#ifdef MOC_CROSS_COMPILED
+ − 1203
QSKIP("Not tested when cross-compiled", SkipAll);
+ − 1204
#endif
+ − 1205
#if defined(Q_OS_LINUX) && defined(Q_CC_GNU) && !defined(QT_NO_PROCESS)
+ − 1206
QProcess proc;
+ − 1207
proc.start("moc", QStringList(srcify("pure-virtual-signals.h")));
+ − 1208
QVERIFY(proc.waitForFinished());
+ − 1209
QCOMPARE(proc.exitCode(), 0);
+ − 1210
QByteArray mocOut = proc.readAllStandardOutput();
+ − 1211
QVERIFY(!mocOut.isEmpty());
+ − 1212
QString mocWarning = QString::fromLocal8Bit(proc.readAllStandardError());
+ − 1213
QCOMPARE(mocWarning, QString(SRCDIR) + QString("/pure-virtual-signals.h:48: Warning: Signals cannot be declared virtual\n") +
+ − 1214
QString(SRCDIR) + QString("/pure-virtual-signals.h:50: Warning: Signals cannot be declared virtual\n"));
+ − 1215
#else
+ − 1216
QSKIP("Only tested on linux/gcc", SkipAll);
+ − 1217
#endif
+ − 1218
}
+ − 1219
3
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 1220
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 1221
class QTBUG5590_DummyObject: public QObject
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 1222
{
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 1223
Q_OBJECT
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 1224
Q_PROPERTY(bool dummy)
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 1225
};
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 1226
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 1227
class QTBUG5590_PropertyObject: public QTBUG5590_DummyObject
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 1228
{
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 1229
Q_OBJECT
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 1230
Q_PROPERTY(int value READ value WRITE setValue)
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 1231
Q_PROPERTY(int value2 READ value2 WRITE setValue2)
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 1232
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 1233
public:
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 1234
QTBUG5590_PropertyObject() : m_value(85), m_value2(40) { }
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 1235
int value() const { return m_value; }
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 1236
void setValue(int value) { m_value = value; }
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 1237
int value2() const { return m_value2; }
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 1238
void setValue2(int value) { m_value2 = value; }
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 1239
private:
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 1240
int m_value, m_value2;
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 1241
};
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 1242
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 1243
void tst_Moc::QTBUG5590_dummyProperty()
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 1244
{
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 1245
QTBUG5590_PropertyObject o;
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 1246
QCOMPARE(o.property("value").toInt(), 85);
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 1247
QCOMPARE(o.property("value2").toInt(), 40);
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 1248
o.setProperty("value", 32);
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 1249
QCOMPARE(o.value(), 32);
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 1250
o.setProperty("value2", 82);
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 1251
QCOMPARE(o.value2(), 82);
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 1252
}
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 1253
0
+ − 1254
QTEST_APPLESS_MAIN(tst_Moc)
+ − 1255
#include "tst_moc.moc"
+ − 1256
+ − 1257
+ − 1258