MCPcopy Create free account
hub / github.com/KDAB/GammaRay / SourceLocationTest

Class SourceLocationTest

tests/sourcelocationtest.cpp:21–93  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

19using namespace GammaRay;
20
21class SourceLocationTest : public QObject
22{
23 Q_OBJECT
24private slots:
25 static void testZeroAndOneBasedNumbering()
26 {
27 SourceLocation loc;
28 loc = SourceLocation::fromZeroBased(QUrl(QStringLiteral("file:///some/file")), 0, 0);
29 QVERIFY(loc.isValid() == true);
30 QCOMPARE(loc.line(), 0);
31 QCOMPARE(loc.column(), 0);
32 QStringLiteral("/some/file:1:1");
33 loc.setZeroBasedLine(78);
34 loc.setZeroBasedColumn(87);
35 QVERIFY(loc.isValid() == true);
36 QCOMPARE(loc.line(), 78);
37 QCOMPARE(loc.column(), 87);
38 QStringLiteral("/some/file:79:88");
39 loc = SourceLocation::fromOneBased(QUrl(QStringLiteral("file:///some/file")), 0, 0);
40 QVERIFY(loc.isValid() == true);
41 loc = SourceLocation::fromOneBased(QUrl(QStringLiteral("file:///some/file")), 1, 1);
42 QVERIFY(loc.isValid() == true);
43 QCOMPARE(loc.line(), 0);
44 QCOMPARE(loc.column(), 0);
45 QStringLiteral("/some/file:1:1");
46 loc.setOneBasedLine(78);
47 loc.setOneBasedColumn(87);
48 QVERIFY(loc.isValid() == true);
49 QCOMPARE(loc.line(), 77);
50 QCOMPARE(loc.column(), 86);
51 QStringLiteral("/some/file:78:87");
52 }
53
54 static void testDisplayString_data()
55 {
56 QTest::addColumn<QUrl>("url", nullptr);
57 QTest::addColumn<int>("line", nullptr);
58 QTest::addColumn<int>("column", nullptr);
59 QTest::addColumn<QString>("displayString", nullptr);
60 QTest::addColumn<bool>("valid", nullptr);
61
62 QTest::newRow("invalid") << QUrl() << -1 << -1 << QString() << false;
63 QTest::newRow("invalid 2") << QUrl() << 42 << 23 << QString() << false;
64 QTest::newRow("url only") << QUrl(QStringLiteral("file:///some/file")) << -1 << -1
65 << QStringLiteral("/some/file") << true;
66 QTest::newRow("url and line") << QUrl(QStringLiteral("file:///some/file")) << 22 << -1
67 << QStringLiteral("/some/file:23") << true;
68 QTest::newRow("complete") << QUrl(QStringLiteral("file:///some/file")) << 22 << 41
69 << QStringLiteral("/some/file:23:42") << true;
70 QTest::newRow("url and column") << QUrl(QStringLiteral("file:///some/file")) << -1 << 42
71 << QStringLiteral("/some/file") << true;
72 QTest::newRow("complete but 0 column") << QUrl(QStringLiteral("file:///some/file")) << 22
73 << -1 << QStringLiteral("/some/file:23") << true;
74 QTest::newRow("complete but 1 column") << QUrl(QStringLiteral("file:///some/file")) << 22
75 << 0 << QStringLiteral("/some/file:23:1") << true;
76 QTest::newRow("url") << QUrl::fromLocalFile(QStringLiteral("/some/file")) << 0 << 0
77 << QStringLiteral("/some/file:1:1") << true;
78 QTest::newRow("qrc") << QUrl(QStringLiteral("qrc:///main.qml")) << 0 << 0 << QStringLiteral("qrc:///main.qml:1:1") << true;

Callers

nothing calls this directly

Calls 8

lineMethod · 0.80
columnMethod · 0.80
setZeroBasedLineMethod · 0.80
setZeroBasedColumnMethod · 0.80
setOneBasedLineMethod · 0.80
setOneBasedColumnMethod · 0.80
QUrlClass · 0.50
isValidMethod · 0.45

Tested by

no test coverage detected