File: testlocationtable.cpp

package info (click to toggle)
kdevelop-pg-qt 2.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 6,284 kB
  • sloc: cpp: 22,743; lex: 928; ansic: 716; yacc: 615; ruby: 68; sh: 14; lisp: 10; fortran: 6; makefile: 2
file content (88 lines) | stat: -rw-r--r-- 1,607 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*
    SPDX-FileCopyrightText: 2009 Milian Wolff <mail@milianw.de>

    SPDX-License-Identifier: GPL-2.0-or-later
*/

#include "testlocationtable.h"

#include <cstdlib>
#include <QTest>
#include <QDebug>

#include <kdev-pg-location-table.h>

namespace KDevPG
{

void TestLocationTable::initTestCase()
{
}

void TestLocationTable::newline()
{
  LocationTable table;
  qint64 offset = 100;
  table.newline(offset);
  qint64 line;
  qint64 column;
  table.positionAt(offset, &line, &column);
  QCOMPARE(line, 0ll);
  QCOMPARE(column, offset);
}

void TestLocationTable::normalAccess()
{
  LocationTable table;
  table.newline(10);
  table.newline(20);
  qint64 line;
  qint64 column;

  qint64 myOffset = 15;
  table.positionAt(myOffset, &line, &column);
  QCOMPARE(line, 1ll);
  QCOMPARE(column, myOffset - table[1]);

  table.positionAt(0, &line, &column);
  QCOMPARE(line, 0ll);
  QCOMPARE(column, 0ll);
}

void TestLocationTable::overflow()
{
  LocationTable table;
  table.newline(10);
  table.newline(20);
  qint64 line;
  qint64 column;
  qint64 myOffset = 200;
  table.positionAt(myOffset, &line, &column);
  QCOMPARE(line, 2ll);
  QCOMPARE(column, myOffset - table[2]);
}

void TestLocationTable::underflow()
{
  LocationTable table;
  table.newline(10);
  table.newline(20);
  qint64 line;
  qint64 column;
  {
    table.positionAt(-1, &line, &column);
    QCOMPARE(line, -1ll);
    QCOMPARE(column, -1ll);
  }
  {
    table.positionAt(-1123, &line, &column);
    QCOMPARE(line, -1ll);
    QCOMPARE(column, -1ll);
  }
}

}

QTEST_MAIN(KDevPG::TestLocationTable)

#include "moc_testlocationtable.cpp"