~ubuntu-branches/debian/sid/kdevelop/sid

« back to all changes in this revision

Viewing changes to languages/cpp/tests/test_cppcodecompletion.cpp

  • Committer: Package Import Robot
  • Author(s): Pino Toscano, Andreas Cord-Landwehr
  • Date: 2014-01-18 10:13:08 UTC
  • mfrom: (1.3.21)
  • Revision ID: package-import@ubuntu.com-20140118101308-3o17vgglnms0emch
Tags: 4:4.5.2-1
* Team upload.
* New upstream release.

[ Andreas Cord-Landwehr ]
* Remove patch okteta_optional_structures_tool.diff, applied upstream.
* Bump build dependency for kdevplatform-dev to 1.5.2.
* Bump Standards-Version to 3.9.5: no changes needed.
* Update debian/watch file to track xz compressed tarballs (Closes: #731896)

Show diffs side-by-side

added added

removed removed

Lines of Context:
359
359
 
360
360
void TestCppCodeCompletion::testMemberAccess()
361
361
{
362
 
  QByteArray method = "template<class T1, class T2> class T { public: T1 ta(); class U { public: class V{ };  }; }; class X { public: X(){}; int a(int a, T<int,int> b); int b;}; T<int,int> t; X* getX() { }";
 
362
  QByteArray method = "template<class T1, class T2> class T { public: T1 ta(); class U { public: class V{ };  }; };"
 
363
                      "class X { public: X(){}; int a(int a, T<int,int> b); int b;};"
 
364
                      "T<int,int> t;"
 
365
                      "X* getX() { }"
 
366
                      "class Z { public: Z() = delete; static int a(int b); };";
363
367
  TopDUContext* top = parse(method, DumpNone);
364
368
  int ctxt = 4;
365
369
  DUChainWriteLocker lock(DUChain::lock());
381
385
  CompletionItemTester testColons2(top->childContexts()[ctxt], "T::U::");
382
386
  QCOMPARE(testColons2.names, QStringList() << "V");
383
387
  QCOMPARE(testColons2.completionContext->accessType(), Cpp::CodeCompletionContext::StaticMemberChoose);
 
388
  CompletionItemTester testDeleted(top->childContexts()[ctxt], "Z::");
 
389
  QCOMPARE(testDeleted.names, QStringList() << "a");
 
390
  QCOMPARE(testDeleted.completionContext->accessType(), Cpp::CodeCompletionContext::StaticMemberChoose);
384
391
  release(top);
385
392
}
386
393
 
1021
1028
  }
1022
1029
}
1023
1030
 
 
1031
void TestCppCodeCompletion::testConstructorUsageCompletion_data()
 
1032
{
 
1033
  QTest::addColumn<QString>("code");        // existing source code
 
1034
  QTest::addColumn<QStringList>("args");        // completion arguments
 
1035
  QTest::addColumn<QStringList>("not_args");    // forbidden completion arguments
 
1036
 
 
1037
  // only the default constructor is present
 
1038
  QTest::newRow("only default")
 
1039
    << "class A { A(); };"
 
1040
    << (QStringList() << "()")
 
1041
    << QStringList();
 
1042
  // the default constructor and one overload
 
1043
  QTest::newRow("Default and int")
 
1044
    << "class A { A(); A(int); };"
 
1045
    << (QStringList() << "()" << "(int)")
 
1046
    << QStringList();
 
1047
  // the default constructor and two overloads
 
1048
  QTest::newRow("Default, int and float")
 
1049
    << "class A { A(); A(int); A(float); };"
 
1050
    << (QStringList() << "()" << "(int)" << "(float)")
 
1051
    << QStringList();
 
1052
  // deleted default constructor and two overloads
 
1053
  QTest::newRow("no default, int and float")
 
1054
    << "class A { A() = delete; A(int); A(float); };"
 
1055
    << (QStringList() << "(int)" << "(float)")
 
1056
    << (QStringList() << "()");
 
1057
  // the default and copy constructors are present
 
1058
  QTest::newRow("default and copy")
 
1059
    << "class A { A(); A(const A&); };"
 
1060
    << (QStringList() << "()" << "(const A&)")
 
1061
    << QStringList();
 
1062
  // the default and copy constructors are deleted
 
1063
  QTest::newRow("default and copy")
 
1064
    << "class A { A() = delete; A(const A&) = delete; };"
 
1065
    << QStringList()
 
1066
    << (QStringList() << "()" << "(const A&)");
 
1067
  // the default and copy constructors are deleted, but another one is present
 
1068
  QTest::newRow("default and copy")
 
1069
    << "class A { A() = delete; A(const A&) = delete; A(int); };"
 
1070
    << (QStringList() << "(int)")
 
1071
    << (QStringList() << "()" << "(const A&)");
 
1072
}
 
1073
 
 
1074
void TestCppCodeCompletion::testConstructorUsageCompletion()
 
1075
{
 
1076
  QFETCH(QString, code);
 
1077
  QFETCH(QStringList, args);
 
1078
  QFETCH(QStringList, not_args);
 
1079
 
 
1080
  TopDUContext* context = parse( code.toAscii(), DumpNone /*DumpDUChain | DumpAST */);
 
1081
  DUChainWriteLocker lock(DUChain::lock());
 
1082
 
 
1083
  CompletionItemTester tester(context, "void k() { A *a = new A(");
 
1084
 
 
1085
  QStringList foundargs;
 
1086
  for (int i = 0; i < tester.items.count(); i++)
 
1087
    foundargs << tester.itemData(i, KTextEditor::CodeCompletionModel::Arguments).toString();
 
1088
  qDebug() << foundargs << args << not_args;
 
1089
  foreach(const QString &arg, args)
 
1090
    QVERIFY(foundargs.contains(arg));
 
1091
  foreach(const QString &arg, not_args)
 
1092
    QVERIFY(!foundargs.contains(arg));
 
1093
 
 
1094
  release(context);
 
1095
}
 
1096
 
1024
1097
void TestCppCodeCompletion::testParentConstructor_data()
1025
1098
{
1026
1099
  QTest::addColumn<QString>("code");        // existing source code
3101
3174
  codeToArgList.insert("void foo(int arg[][1]){}", "(int arg[][1])");
3102
3175
  codeToArgList.insert("void foo(int arg[1][1]){}", "(int arg[1][1])");
3103
3176
  codeToArgList.insert("void foo(int arg[][1][1]){}", "(int arg[][1][1])");
 
3177
  codeToArgList.insert("void foo(void){}", "(void)");
 
3178
  codeToArgList.insert("void foo(int){}", "(int)");
3104
3179
  QMap< QByteArray, QString >::const_iterator it = codeToArgList.constBegin();
3105
3180
  while (it != codeToArgList.constEnd()){
3106
3181
    qDebug() << "input function is:" << it.key();