cppcodegen_test.cpp 19.1 KB
Newer Older
Bill King's avatar
Bill King committed
1 2 3 4 5 6
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
**
7
** Contact: Nokia Corporation (qt-info@nokia.com)
Bill King's avatar
Bill King committed
8 9 10 11
**
**
** GNU Lesser General Public License Usage
**
hjk's avatar
hjk committed
12 13 14 15 16 17
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this file.
** Please review the following information to ensure the GNU Lesser General
** Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
Bill King's avatar
Bill King committed
18 19
**
** In addition, as a special exception, Nokia gives you certain additional
hjk's avatar
hjk committed
20
** rights. These rights are described in the Nokia Qt LGPL Exception
Bill King's avatar
Bill King committed
21 22
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
23 24 25 26 27
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
Bill King's avatar
Bill King committed
28
** If you have questions regarding the use of this file, please contact
29
** Nokia at qt-info@nokia.com.
Bill King's avatar
Bill King committed
30 31 32
**
**************************************************************************/

33 34
#include "cpptoolsplugin.h"

35 36 37 38 39 40 41
#include <AST.h>
#include <Control.h>
#include <CppDocument.h>
#include <DiagnosticClient.h>
#include <Scope.h>
#include <TranslationUnit.h>
#include <Literals.h>
Roberto Raggi's avatar
Compile  
Roberto Raggi committed
42
#include <Bind.h>
43
#include <Symbols.h>
44 45
#include <cpptools/insertionpointlocator.h>
#include <cpptools/cpprefactoringchanges.h>
46 47
#include <cpptools/cpptoolsplugin.h>
#include <extensionsystem/pluginmanager.h>
48
#include <utils/fileutils.h>
49 50 51 52

#include <QtTest>
#include <QtDebug>
#include <QTextDocument>
53
#include <QDir>
54

55 56 57 58
/*!
    Tests for various parts of the code generation. Well, okay, currently it only
    tests the InsertionPointLocator.
 */
59
using namespace CPlusPlus;
60
using namespace CppTools;
61
using namespace CppTools::Internal;
62

63 64 65
/*!
    Should insert at line 3, column 1, with "public:\n" as prefix and without suffix.
 */
66
void CppToolsPlugin::test_codegen_public_in_empty_class()
67 68 69 70
{
    const QByteArray src = "\n"
            "class Foo\n" // line 1
            "{\n"
71
            "};\n"
72 73
            "\n";

74
    Document::Ptr doc = Document::create("public_in_empty_class");
75 76 77 78 79 80 81
    doc->setSource(src);
    doc->parse();
    doc->check();

    QCOMPARE(doc->diagnosticMessages().size(), 0);
    QCOMPARE(doc->globalSymbolCount(), 1U);

82 83 84 85 86 87 88
    Class *foo = doc->globalSymbolAt(0)->asClass();
    QVERIFY(foo);
    QCOMPARE(foo->line(), 1U);
    QCOMPARE(foo->column(), 7U);

    Snapshot snapshot;
    snapshot.insert(doc);
89
    CppRefactoringChanges changes(snapshot);
90
    InsertionPointLocator find(changes);
91
    InsertionLocation loc = find.methodDeclarationInClass(
92 93
                doc->fileName(),
                foo,
94
                InsertionPointLocator::Public);
95
    QVERIFY(loc.isValid());
96
    QCOMPARE(loc.prefix(), QLatin1String("public:\n"));
97
    QVERIFY(loc.suffix().isEmpty());
98
    QCOMPARE(loc.line(), 3U);
99 100 101
    QCOMPARE(loc.column(), 1U);
}

102 103 104
/*!
    Should insert at line 3, column 1, without prefix and without suffix.
 */
105
void CppToolsPlugin::test_codegen_public_in_nonempty_class()
106 107 108 109
{
    const QByteArray src = "\n"
            "class Foo\n" // line 1
            "{\n"
110 111
            "public:\n"   // line 3
            "};\n"        // line 4
112 113
            "\n";

114
    Document::Ptr doc = Document::create("public_in_nonempty_class");
115 116 117 118 119 120 121
    doc->setSource(src);
    doc->parse();
    doc->check();

    QCOMPARE(doc->diagnosticMessages().size(), 0);
    QCOMPARE(doc->globalSymbolCount(), 1U);

122 123 124 125
    Class *foo = doc->globalSymbolAt(0)->asClass();
    QVERIFY(foo);
    QCOMPARE(foo->line(), 1U);
    QCOMPARE(foo->column(), 7U);
126

127 128
    Snapshot snapshot;
    snapshot.insert(doc);
129
    CppRefactoringChanges changes(snapshot);
130
    InsertionPointLocator find(changes);
131
    InsertionLocation loc = find.methodDeclarationInClass(
132 133
                doc->fileName(),
                foo,
134
                InsertionPointLocator::Public);
135
    QVERIFY(loc.isValid());
136
    QVERIFY(loc.prefix().isEmpty());
137
    QVERIFY(loc.suffix().isEmpty());
138
    QCOMPARE(loc.line(), 4U);
139 140 141
    QCOMPARE(loc.column(), 1U);
}

142 143 144
/*!
    Should insert at line 3, column 1, with "public:\n" as prefix and "\n suffix.
 */
145
void CppToolsPlugin::test_codegen_public_before_protected()
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
{
    const QByteArray src = "\n"
            "class Foo\n"  // line 1
            "{\n"
            "protected:\n" // line 3
            "};\n"
            "\n";

    Document::Ptr doc = Document::create("public_before_protected");
    doc->setSource(src);
    doc->parse();
    doc->check();

    QCOMPARE(doc->diagnosticMessages().size(), 0);
    QCOMPARE(doc->globalSymbolCount(), 1U);

162 163 164 165
    Class *foo = doc->globalSymbolAt(0)->asClass();
    QVERIFY(foo);
    QCOMPARE(foo->line(), 1U);
    QCOMPARE(foo->column(), 7U);
166

167 168
    Snapshot snapshot;
    snapshot.insert(doc);
169
    CppRefactoringChanges changes(snapshot);
170
    InsertionPointLocator find(changes);
171
    InsertionLocation loc = find.methodDeclarationInClass(
172 173
                doc->fileName(),
                foo,
174
                InsertionPointLocator::Public);
175 176 177 178 179 180 181
    QVERIFY(loc.isValid());
    QCOMPARE(loc.prefix(), QLatin1String("public:\n"));
    QCOMPARE(loc.suffix(), QLatin1String("\n"));
    QCOMPARE(loc.column(), 1U);
    QCOMPARE(loc.line(), 3U);
}

182 183 184 185
/*!
    Should insert at line 4, column 1, with "private:\n" as prefix and without
    suffix.
 */
186
void CppToolsPlugin::test_codegen_private_after_protected()
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202
{
    const QByteArray src = "\n"
            "class Foo\n"  // line 1
            "{\n"
            "protected:\n" // line 3
            "};\n"
            "\n";

    Document::Ptr doc = Document::create("private_after_protected");
    doc->setSource(src);
    doc->parse();
    doc->check();

    QCOMPARE(doc->diagnosticMessages().size(), 0);
    QCOMPARE(doc->globalSymbolCount(), 1U);

203 204 205 206
    Class *foo = doc->globalSymbolAt(0)->asClass();
    QVERIFY(foo);
    QCOMPARE(foo->line(), 1U);
    QCOMPARE(foo->column(), 7U);
207

208 209
    Snapshot snapshot;
    snapshot.insert(doc);
210
    CppRefactoringChanges changes(snapshot);
211
    InsertionPointLocator find(changes);
212
    InsertionLocation loc = find.methodDeclarationInClass(
213 214
                doc->fileName(),
                foo,
215
                InsertionPointLocator::Private);
216 217 218 219 220 221 222
    QVERIFY(loc.isValid());
    QCOMPARE(loc.prefix(), QLatin1String("private:\n"));
    QVERIFY(loc.suffix().isEmpty());
    QCOMPARE(loc.column(), 1U);
    QCOMPARE(loc.line(), 4U);
}

223 224 225 226
/*!
    Should insert at line 4, column 1, with "protected:\n" as prefix and without
    suffix.
 */
227
void CppToolsPlugin::test_codegen_protected_in_nonempty_class()
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243
{
    const QByteArray src = "\n"
            "class Foo\n" // line 1
            "{\n"
            "public:\n"   // line 3
            "};\n"        // line 4
            "\n";

    Document::Ptr doc = Document::create("protected_in_nonempty_class");
    doc->setSource(src);
    doc->parse();
    doc->check();

    QCOMPARE(doc->diagnosticMessages().size(), 0);
    QCOMPARE(doc->globalSymbolCount(), 1U);

244 245 246 247
    Class *foo = doc->globalSymbolAt(0)->asClass();
    QVERIFY(foo);
    QCOMPARE(foo->line(), 1U);
    QCOMPARE(foo->column(), 7U);
248

249 250
    Snapshot snapshot;
    snapshot.insert(doc);
251
    CppRefactoringChanges changes(snapshot);
252
    InsertionPointLocator find(changes);
253
    InsertionLocation loc = find.methodDeclarationInClass(
254 255
                doc->fileName(),
                foo,
256
                InsertionPointLocator::Protected);
257 258 259 260 261 262 263
    QVERIFY(loc.isValid());
    QCOMPARE(loc.prefix(), QLatin1String("protected:\n"));
    QVERIFY(loc.suffix().isEmpty());
    QCOMPARE(loc.column(), 1U);
    QCOMPARE(loc.line(), 4U);
}

264 265 266
/*!
    Should insert at line 4, column 1, with "protected\n" as prefix and "\n" suffix.
 */
267
void CppToolsPlugin::test_codegen_protected_between_public_and_private()
268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284
{
    const QByteArray src = "\n"
            "class Foo\n" // line 1
            "{\n"
            "public:\n"   // line 3
            "private:\n"  // line 4
            "};\n"        // line 5
            "\n";

    Document::Ptr doc = Document::create("protected_betwee_public_and_private");
    doc->setSource(src);
    doc->parse();
    doc->check();

    QCOMPARE(doc->diagnosticMessages().size(), 0);
    QCOMPARE(doc->globalSymbolCount(), 1U);

285 286 287 288
    Class *foo = doc->globalSymbolAt(0)->asClass();
    QVERIFY(foo);
    QCOMPARE(foo->line(), 1U);
    QCOMPARE(foo->column(), 7U);
289

290 291
    Snapshot snapshot;
    snapshot.insert(doc);
292
    CppRefactoringChanges changes(snapshot);
293
    InsertionPointLocator find(changes);
294
    InsertionLocation loc = find.methodDeclarationInClass(
295 296
                doc->fileName(),
                foo,
297
                InsertionPointLocator::Protected);
298 299 300 301 302 303 304
    QVERIFY(loc.isValid());
    QCOMPARE(loc.prefix(), QLatin1String("protected:\n"));
    QCOMPARE(loc.suffix(), QLatin1String("\n"));
    QCOMPARE(loc.column(), 1U);
    QCOMPARE(loc.line(), 4U);
}

305 306 307 308 309 310 311
/*!
    Should insert at line 18, column 1, with "private slots:\n" as prefix and "\n"
    as suffix.

    This is the typical Qt Designer case, with test-input like what the integration
    generates.
 */
312
void CppToolsPlugin::test_codegen_qtdesigner_integration()
313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345
{
    const QByteArray src = "/**** Some long (C)opyright notice ****/\n"
            "#ifndef MAINWINDOW_H\n"
            "#define MAINWINDOW_H\n"
            "\n"
            "#include <QMainWindow>\n"
            "\n"
            "namespace Ui {\n"
            "    class MainWindow;\n"
            "}\n"
            "\n"
            "class MainWindow : public QMainWindow\n" // line 10
            "{\n"
            "    Q_OBJECT\n"
            "\n"
            "public:\n" // line 14
            "    explicit MainWindow(QWidget *parent = 0);\n"
            "    ~MainWindow();\n"
            "\n"
            "private:\n" // line 18
            "    Ui::MainWindow *ui;\n"
            "};\n"
            "\n"
            "#endif // MAINWINDOW_H\n";

    Document::Ptr doc = Document::create("qtdesigner_integration");
    doc->setSource(src);
    doc->parse();
    doc->check();

    QCOMPARE(doc->diagnosticMessages().size(), 0);
    QCOMPARE(doc->globalSymbolCount(), 2U);

346 347 348 349
    Class *foo = doc->globalSymbolAt(1)->asClass();
    QVERIFY(foo);
    QCOMPARE(foo->line(), 10U);
    QCOMPARE(foo->column(), 7U);
350

351 352
    Snapshot snapshot;
    snapshot.insert(doc);
353
    CppRefactoringChanges changes(snapshot);
354
    InsertionPointLocator find(changes);
355
    InsertionLocation loc = find.methodDeclarationInClass(
356 357
                doc->fileName(),
                foo,
358
                InsertionPointLocator::PrivateSlot);
359 360 361 362 363 364 365
    QVERIFY(loc.isValid());
    QCOMPARE(loc.prefix(), QLatin1String("private slots:\n"));
    QCOMPARE(loc.suffix(), QLatin1String("\n"));
    QCOMPARE(loc.line(), 18U);
    QCOMPARE(loc.column(), 1U);
}

366
void CppToolsPlugin::test_codegen_definition_empty_class()
367 368 369 370 371 372 373 374 375 376 377 378
{
    const QByteArray srcText = "\n"
            "class Foo\n"  // line 1
            "{\n"
            "void foo();\n" // line 3
            "};\n"
            "\n";

    const QByteArray dstText = "\n"
            "int x;\n"  // line 1
            "\n";

379
    Document::Ptr src = Document::create(QDir::tempPath() + QLatin1String("/file.h"));
380 381 382 383 384 385 386 387 388
    Utils::FileSaver srcSaver(src->fileName());
    srcSaver.write(srcText);
    srcSaver.finalize();
    src->setSource(srcText);
    src->parse();
    src->check();
    QCOMPARE(src->diagnosticMessages().size(), 0);
    QCOMPARE(src->globalSymbolCount(), 1U);

389
    Document::Ptr dst = Document::create(QDir::tempPath() + QLatin1String("/file.cpp"));
390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417
    Utils::FileSaver dstSaver(dst->fileName());
    dstSaver.write(dstText);
    dstSaver.finalize();
    dst->setSource(dstText);
    dst->parse();
    dst->check();
    QCOMPARE(dst->diagnosticMessages().size(), 0);
    QCOMPARE(dst->globalSymbolCount(), 1U);

    Snapshot snapshot;
    snapshot.insert(src);
    snapshot.insert(dst);

    Class *foo = src->globalSymbolAt(0)->asClass();
    QVERIFY(foo);
    QCOMPARE(foo->line(), 1U);
    QCOMPARE(foo->column(), 7U);
    QCOMPARE(foo->memberCount(), 1U);
    Declaration *decl = foo->memberAt(0)->asDeclaration();
    QVERIFY(decl);
    QCOMPARE(decl->line(), 3U);
    QCOMPARE(decl->column(), 6U);

    CppRefactoringChanges changes(snapshot);
    InsertionPointLocator find(changes);
    QList<InsertionLocation> locList = find.methodDefinition(decl);
    QVERIFY(locList.size() == 1);
    InsertionLocation loc = locList.first();
418
    QCOMPARE(loc.fileName(), dst->fileName());
419 420 421 422 423 424
    QCOMPARE(loc.prefix(), QLatin1String("\n\n"));
    QCOMPARE(loc.suffix(), QString());
    QCOMPARE(loc.line(), 1U);
    QCOMPARE(loc.column(), 7U);
}

425
void CppToolsPlugin::test_codegen_definition_first_member()
426 427 428 429 430 431 432 433 434
{
    const QByteArray srcText = "\n"
            "class Foo\n"  // line 1
            "{\n"
            "void foo();\n" // line 3
            "void bar();\n" // line 4
            "};\n"
            "\n";

435 436 437 438 439 440 441 442 443 444
    const QByteArray dstText = QString(
                "\n"
                "#include \"%1/file.h\"\n" // line 1
                "int x;\n"
                "\n"
                "void Foo::bar()\n" // line 4
                "{\n"
                "\n"
                "}\n"
                "\n"
445
                "int y;\n").arg(QDir::tempPath()).toLatin1();
446

447
    Document::Ptr src = Document::create(QDir::tempPath() + QLatin1String("/file.h"));
448 449 450 451 452 453 454 455 456
    Utils::FileSaver srcSaver(src->fileName());
    srcSaver.write(srcText);
    srcSaver.finalize();
    src->setSource(srcText);
    src->parse();
    src->check();
    QCOMPARE(src->diagnosticMessages().size(), 0);
    QCOMPARE(src->globalSymbolCount(), 1U);

457
    Document::Ptr dst = Document::create(QDir::tempPath() + QLatin1String("/file.cpp"));
458
    dst->addIncludeFile(src->fileName(), 1);
459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486
    Utils::FileSaver dstSaver(dst->fileName());
    dstSaver.write(dstText);
    dstSaver.finalize();
    dst->setSource(dstText);
    dst->parse();
    dst->check();
    QCOMPARE(dst->diagnosticMessages().size(), 0);
    QCOMPARE(dst->globalSymbolCount(), 3U);

    Snapshot snapshot;
    snapshot.insert(src);
    snapshot.insert(dst);

    Class *foo = src->globalSymbolAt(0)->asClass();
    QVERIFY(foo);
    QCOMPARE(foo->line(), 1U);
    QCOMPARE(foo->column(), 7U);
    QCOMPARE(foo->memberCount(), 2U);
    Declaration *decl = foo->memberAt(0)->asDeclaration();
    QVERIFY(decl);
    QCOMPARE(decl->line(), 3U);
    QCOMPARE(decl->column(), 6U);

    CppRefactoringChanges changes(snapshot);
    InsertionPointLocator find(changes);
    QList<InsertionLocation> locList = find.methodDefinition(decl);
    QVERIFY(locList.size() == 1);
    InsertionLocation loc = locList.first();
487
    QCOMPARE(loc.fileName(), dst->fileName());
488 489 490 491 492 493
    QCOMPARE(loc.line(), 4U);
    QCOMPARE(loc.column(), 1U);
    QCOMPARE(loc.suffix(), QLatin1String("\n\n"));
    QCOMPARE(loc.prefix(), QString());
}

494
void CppToolsPlugin::test_codegen_definition_last_member()
495 496 497 498 499 500 501 502 503
{
    const QByteArray srcText = "\n"
            "class Foo\n"  // line 1
            "{\n"
            "void foo();\n" // line 3
            "void bar();\n" // line 4
            "};\n"
            "\n";

504 505 506 507 508 509 510 511 512 513
    const QByteArray dstText = QString(
                "\n"
                "#include \"%1/file.h\"\n" // line 1
                "int x;\n"
                "\n"
                "void Foo::foo()\n" // line 4
                "{\n"
                "\n"
                "}\n" // line 7
                "\n"
514
                "int y;\n").arg(QDir::tempPath()).toLatin1();
515

516
    Document::Ptr src = Document::create(QDir::tempPath() + QLatin1String("/file.h"));
517 518 519 520 521 522 523 524 525
    Utils::FileSaver srcSaver(src->fileName());
    srcSaver.write(srcText);
    srcSaver.finalize();
    src->setSource(srcText);
    src->parse();
    src->check();
    QCOMPARE(src->diagnosticMessages().size(), 0);
    QCOMPARE(src->globalSymbolCount(), 1U);

526
    Document::Ptr dst = Document::create(QDir::tempPath() + QLatin1String("/file.cpp"));
527
    dst->addIncludeFile(src->fileName(), 1);
528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555
    Utils::FileSaver dstSaver(dst->fileName());
    dstSaver.write(dstText);
    dstSaver.finalize();
    dst->setSource(dstText);
    dst->parse();
    dst->check();
    QCOMPARE(dst->diagnosticMessages().size(), 0);
    QCOMPARE(dst->globalSymbolCount(), 3U);

    Snapshot snapshot;
    snapshot.insert(src);
    snapshot.insert(dst);

    Class *foo = src->globalSymbolAt(0)->asClass();
    QVERIFY(foo);
    QCOMPARE(foo->line(), 1U);
    QCOMPARE(foo->column(), 7U);
    QCOMPARE(foo->memberCount(), 2U);
    Declaration *decl = foo->memberAt(1)->asDeclaration();
    QVERIFY(decl);
    QCOMPARE(decl->line(), 4U);
    QCOMPARE(decl->column(), 6U);

    CppRefactoringChanges changes(snapshot);
    InsertionPointLocator find(changes);
    QList<InsertionLocation> locList = find.methodDefinition(decl);
    QVERIFY(locList.size() == 1);
    InsertionLocation loc = locList.first();
556
    QCOMPARE(loc.fileName(), dst->fileName());
557 558 559 560 561 562
    QCOMPARE(loc.line(), 7U);
    QCOMPARE(loc.column(), 2U);
    QCOMPARE(loc.prefix(), QLatin1String("\n\n"));
    QCOMPARE(loc.suffix(), QString());
}

563
void CppToolsPlugin::test_codegen_definition_middle_member()
564 565 566 567 568 569 570 571 572 573
{
    const QByteArray srcText = "\n"
            "class Foo\n"  // line 1
            "{\n"
            "void foo();\n" // line 3
            "void bar();\n" // line 4
            "void car();\n" // line 5
            "};\n"
            "\n";

574 575 576 577 578 579 580 581 582 583 584 585 586 587 588
    const QByteArray dstText = QString(
                "\n"
                "#include \"%1/file.h\"\n" // line 1
                "int x;\n"
                "\n"
                "void Foo::foo()\n" // line 4
                "{\n"
                "\n"
                "}\n" // line 7
                "\n"
                "void Foo::car()\n" // line 9
                "{\n"
                "\n"
                "}\n"
                "\n"
589
                "int y;\n").arg(QDir::tempPath()).toLatin1();
590

591
    Document::Ptr src = Document::create(QDir::tempPath() + QLatin1String("/file.h"));
592 593 594 595 596 597 598 599 600
    Utils::FileSaver srcSaver(src->fileName());
    srcSaver.write(srcText);
    srcSaver.finalize();
    src->setSource(srcText);
    src->parse();
    src->check();
    QCOMPARE(src->diagnosticMessages().size(), 0);
    QCOMPARE(src->globalSymbolCount(), 1U);

601
    Document::Ptr dst = Document::create(QDir::tempPath() + QLatin1String("/file.cpp"));
602
    dst->addIncludeFile(src->fileName(), 1);
603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630
    Utils::FileSaver dstSaver(dst->fileName());
    dstSaver.write(dstText);
    dstSaver.finalize();
    dst->setSource(dstText);
    dst->parse();
    dst->check();
    QCOMPARE(dst->diagnosticMessages().size(), 0);
    QCOMPARE(dst->globalSymbolCount(), 4U);

    Snapshot snapshot;
    snapshot.insert(src);
    snapshot.insert(dst);

    Class *foo = src->globalSymbolAt(0)->asClass();
    QVERIFY(foo);
    QCOMPARE(foo->line(), 1U);
    QCOMPARE(foo->column(), 7U);
    QCOMPARE(foo->memberCount(), 3U);
    Declaration *decl = foo->memberAt(1)->asDeclaration();
    QVERIFY(decl);
    QCOMPARE(decl->line(), 4U);
    QCOMPARE(decl->column(), 6U);

    CppRefactoringChanges changes(snapshot);
    InsertionPointLocator find(changes);
    QList<InsertionLocation> locList = find.methodDefinition(decl);
    QVERIFY(locList.size() == 1);
    InsertionLocation loc = locList.first();
631
    QCOMPARE(loc.fileName(), dst->fileName());
632 633 634 635 636
    QCOMPARE(loc.line(), 7U);
    QCOMPARE(loc.column(), 2U);
    QCOMPARE(loc.prefix(), QLatin1String("\n\n"));
    QCOMPARE(loc.suffix(), QString());
}