File indexing completed on 2024-04-21 04:36:20

0001 /*
0002     <one line to give the program's name and a brief idea of what it does.>
0003     Copyright (C) <year>  <name of author>
0004 
0005     This program is free software; you can redistribute it and/or modify
0006     it under the terms of the GNU General Public License as published by
0007     the Free Software Foundation; either version 2 of the License, or
0008     (at your option) any later version.
0009 
0010     This program is distributed in the hope that it will be useful,
0011     but WITHOUT ANY WARRANTY; without even the implied warranty of
0012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0013     GNU General Public License for more details.
0014 
0015     You should have received a copy of the GNU General Public License along
0016     with this program; if not, write to the Free Software Foundation, Inc.,
0017     51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
0018 
0019 */
0020 
0021 #include "testlocationtable.h"
0022 
0023 #include <cstdlib>
0024 #include <QTest>
0025 #include <QDebug>
0026 
0027 #include "../include/kdev-pg-location-table.h"
0028 
0029 namespace KDevPG
0030 {
0031 
0032 void TestLocationTable::initTestCase()
0033 {
0034 }
0035 
0036 void TestLocationTable::newline()
0037 {
0038   LocationTable table;
0039   qint64 offset = 100;
0040   table.newline(offset);
0041   qint64 line;
0042   qint64 column;
0043   table.positionAt(offset, &line, &column);
0044   QCOMPARE(line, 0ll);
0045   QCOMPARE(column, offset);
0046 }
0047 
0048 void TestLocationTable::normalAccess()
0049 {
0050   LocationTable table;
0051   table.newline(10);
0052   table.newline(20);
0053   qint64 line;
0054   qint64 column;
0055 
0056   qint64 myOffset = 15;
0057   table.positionAt(myOffset, &line, &column);
0058   QCOMPARE(line, 1ll);
0059   QCOMPARE(column, myOffset - table[1]);
0060 
0061   table.positionAt(0, &line, &column);
0062   QCOMPARE(line, 0ll);
0063   QCOMPARE(column, 0ll);
0064 }
0065 
0066 void TestLocationTable::overflow()
0067 {
0068   LocationTable table;
0069   table.newline(10);
0070   table.newline(20);
0071   qint64 line;
0072   qint64 column;
0073   qint64 myOffset = 200;
0074   table.positionAt(myOffset, &line, &column);
0075   QCOMPARE(line, 2ll);
0076   QCOMPARE(column, myOffset - table[2]);
0077 }
0078 
0079 void TestLocationTable::underflow()
0080 {
0081   LocationTable table;
0082   table.newline(10);
0083   table.newline(20);
0084   qint64 line;
0085   qint64 column;
0086   {
0087     table.positionAt(-1, &line, &column);
0088     QCOMPARE(line, -1ll);
0089     QCOMPARE(column, -1ll);
0090   }
0091   {
0092     table.positionAt(-1123, &line, &column);
0093     QCOMPARE(line, -1ll);
0094     QCOMPARE(column, -1ll);
0095   }
0096 }
0097 
0098 }
0099 
0100 QTEST_MAIN(KDevPG::TestLocationTable)
0101 
0102 #include "moc_testlocationtable.cpp"