C++: Produce copyable debug output in CheckSymbols test

Change-Id: I338352eaf6372316d2dc8f0f3ad961b7e8d8cbdc
Reviewed-by: André Hartmann <aha_1980@gmx.de>
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
This commit is contained in:
Orgad Shaneh
2015-10-22 22:28:29 +03:00
committed by Orgad Shaneh
parent 09417c56bd
commit 3ab5527a83

View File

@@ -47,6 +47,10 @@
Tests CheckSymbols, the "data provider" of the semantic highlighter. Tests CheckSymbols, the "data provider" of the semantic highlighter.
*/ */
// When adding tests, you may want to set this enum
// in order to print out all found uses.
enum { enableListing = 0 };
using namespace CPlusPlus; using namespace CPlusPlus;
using namespace CppTools; using namespace CppTools;
@@ -57,34 +61,27 @@ typedef SemanticHighlighter Highlighting;
typedef QList<Use> UseList; typedef QList<Use> UseList;
Q_DECLARE_METATYPE(UseList) Q_DECLARE_METATYPE(UseList)
#define CASE_STR(val) case Highlighting::val: return "Highlighting::" # val
static QString useKindToString(UseKind useKind) static QString useKindToString(UseKind useKind)
{ {
switch (useKind) { switch (useKind) {
case Highlighting::Unknown: CASE_STR(Unknown);
return QLatin1String("SemanticHighlighter::Unknown"); CASE_STR(TypeUse);
case Highlighting::TypeUse: CASE_STR(LocalUse);
return QLatin1String("SemanticHighlighter::TypeUse"); CASE_STR(FieldUse);
case Highlighting::LocalUse: CASE_STR(EnumerationUse);
return QLatin1String("SemanticHighlighter::LocalUse"); CASE_STR(VirtualMethodUse);
case Highlighting::FieldUse: CASE_STR(LabelUse);
return QLatin1String("SemanticHighlighter::FieldUse"); CASE_STR(MacroUse);
case Highlighting::EnumerationUse: CASE_STR(FunctionUse);
return QLatin1String("SemanticHighlighter::EnumerationUse"); CASE_STR(PseudoKeywordUse);
case Highlighting::VirtualMethodUse: CASE_STR(StringUse);
return QLatin1String("SemanticHighlighter::VirtualMethodUse");
case Highlighting::LabelUse:
return QLatin1String("SemanticHighlighter::LabelUse");
case Highlighting::MacroUse:
return QLatin1String("SemanticHighlighter::MacroUse");
case Highlighting::FunctionUse:
return QLatin1String("SemanticHighlighter::FunctionUse");
case Highlighting::PseudoKeywordUse:
return QLatin1String("SemanticHighlighter::PseudoKeywordUse");
default: default:
QTest::qFail("Unknown UseKind", __FILE__, __LINE__); QTest::qFail("Unknown UseKind", __FILE__, __LINE__);
return QLatin1String("Unknown UseKind"); return QLatin1String("Unknown UseKind");
} }
} }
#undef CASE_STR
// The following two functions are "enhancements" for QCOMPARE(). // The following two functions are "enhancements" for QCOMPARE().
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
@@ -182,14 +179,21 @@ public:
{ {
const int resultCount = future.resultCount(); const int resultCount = future.resultCount();
UseList actualUses; UseList actualUses;
QByteArray expectedInput;
if (enableListing)
expectedInput = _("\n") + _(8, ' ') + "<< (UseList()\n";
for (int i = 0; i < resultCount; ++i) { for (int i = 0; i < resultCount; ++i) {
const Use use = future.resultAt(i); const Use use = future.resultAt(i);
// When adding tests, you may want to uncomment the if (enableListing)
// following line in order to print out all found uses. expectedInput += _(12, ' ') + "<< " + _(QTest::toString(use)) + "\n";
// qDebug() << QTest::toString(use);
actualUses.append(use); actualUses.append(use);
} }
if (enableListing) {
expectedInput.chop(1);
expectedInput += ')';
qDebug() << expectedInput;
}
// Checks // Checks
QVERIFY(resultCount > 0); QVERIFY(resultCount > 0);
QCOMPARE(resultCount, expectedUsesAll.count()); QCOMPARE(resultCount, expectedUsesAll.count());