File indexing completed on 2024-04-28 05:52:39
0001 /* 0002 This file is part of the Okteta Gui library, made within the KDE community. 0003 0004 SPDX-FileCopyrightText: 2006 Friedrich W. H. Kossebau <kossebau@kde.org> 0005 0006 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0007 */ 0008 0009 #include "coordtest.hpp" 0010 0011 // test object 0012 #include <coord.hpp> 0013 // Qt 0014 #include <QTest> 0015 0016 namespace Okteta { 0017 0018 // local variables 0019 static constexpr Line LineIndex = 3; 0020 static constexpr LinePosition Pos = 15; 0021 static constexpr LineSize LineWidth = 19; 0022 static constexpr Address Index = LineIndex * LineWidth + Pos; 0023 static constexpr LinePositionSize MaxPos = LineWidth - 1; 0024 static constexpr LinePositionSize Steps = 5; 0025 0026 void CoordTest::testConstructor() 0027 { 0028 const Coord coord; 0029 0030 QCOMPARE(coord.pos(), 0); 0031 QCOMPARE(coord.line(), 0); 0032 QVERIFY(coord.isValid()); 0033 } 0034 0035 void CoordTest::testSetConstructor() 0036 { 0037 const Coord coord(Pos, LineIndex); 0038 0039 QCOMPARE(coord.pos(), Pos); 0040 QCOMPARE(coord.line(), LineIndex); 0041 QVERIFY(coord.isValid()); 0042 } 0043 0044 void CoordTest::testFromIndexConstructor() 0045 { 0046 const Coord coord = Coord::fromIndex(Index, LineWidth); 0047 0048 QCOMPARE(coord.indexByLineWidth(LineWidth), Index); 0049 QCOMPARE(coord.pos(), Pos); 0050 QCOMPARE(coord.line(), LineIndex); 0051 QVERIFY(coord.isValid()); 0052 } 0053 0054 void CoordTest::testCopyConstructor() 0055 { 0056 const Coord coord(Pos, LineIndex); 0057 const Coord otherCoord(coord); 0058 0059 QCOMPARE(otherCoord.pos(), Pos); 0060 QCOMPARE(otherCoord.line(), LineIndex); 0061 QVERIFY(otherCoord.isValid()); 0062 } 0063 0064 void CoordTest::testEquals() 0065 { 0066 const Coord coord(Pos, LineIndex); 0067 0068 Coord otherCoord(coord); 0069 QVERIFY(otherCoord == coord); 0070 otherCoord.goRight(); 0071 QVERIFY(otherCoord != coord); 0072 } 0073 0074 void CoordTest::testAssign() 0075 { 0076 const Coord coord(Pos, LineIndex); 0077 0078 Coord otherCoord; 0079 otherCoord = coord; 0080 QCOMPARE(otherCoord, coord); 0081 } 0082 0083 void CoordTest::testSetPosLine() 0084 { 0085 Coord coord; 0086 // setPos() 0087 coord.setPos(Pos); 0088 QCOMPARE(coord.pos(), Pos); 0089 // setLine() 0090 coord.setLine(LineIndex); 0091 QCOMPARE(coord.line(), LineIndex); 0092 } 0093 0094 void CoordTest::testSet() 0095 { 0096 Coord coord; 0097 coord.set(Pos, LineIndex); 0098 QCOMPARE(coord.pos(), Pos); 0099 QCOMPARE(coord.line(), LineIndex); 0100 } 0101 0102 void CoordTest::testIsAtStart() 0103 { 0104 Coord coord(0, 0); 0105 0106 QVERIFY(coord.isAtStart()); 0107 coord.set(Pos, LineIndex); 0108 QVERIFY(!coord.isAtStart()); 0109 coord.set(0, 0); 0110 QVERIFY(coord.isAtStart()); 0111 } 0112 0113 void CoordTest::testGotoStart() 0114 { 0115 Coord coord; 0116 coord.gotoStart(); 0117 QVERIFY(coord.isAtStart()); 0118 } 0119 0120 void CoordTest::testGo() 0121 { 0122 const Coord coord(Pos, LineIndex); 0123 Coord otherCoord(coord); 0124 0125 // going clockwise by one 0126 otherCoord.goRight(); otherCoord.goDown(); otherCoord.goLeft(); otherCoord.goUp(); 0127 QCOMPARE(otherCoord, coord); 0128 // going against clockwise by one 0129 otherCoord.goUp(); otherCoord.goLeft(); otherCoord.goDown(); otherCoord.goRight(); 0130 QCOMPARE(otherCoord, coord); 0131 } 0132 0133 void CoordTest::testGoN() 0134 { 0135 const Coord coord(Pos, LineIndex); 0136 Coord otherCoord(coord); 0137 0138 // going clockwise by N 0139 otherCoord.goRight(Steps); otherCoord.goDown(Steps); 0140 otherCoord.goLeft(Steps); otherCoord.goUp(Steps); 0141 QCOMPARE(otherCoord, coord); 0142 // going against clockwise by N 0143 otherCoord.goUp(Steps); otherCoord.goLeft(Steps); 0144 otherCoord.goDown(Steps); otherCoord.goRight(Steps); 0145 QCOMPARE(otherCoord, coord); 0146 } 0147 0148 void CoordTest::testGotoControlled() 0149 { 0150 Coord coord(MaxPos, LineIndex); 0151 Coord otherCoord(coord); 0152 0153 // gotoStartOfNextLine(), goCRight() 0154 coord.gotoStartOfNextLine(); 0155 otherCoord.goCRight(MaxPos); 0156 QCOMPARE(coord, otherCoord); 0157 // gotoEndOfPreviousLine(), goCLeft() 0158 coord.gotoEndOfPreviousLine(MaxPos); 0159 otherCoord.goCLeft(MaxPos); 0160 QCOMPARE(coord, otherCoord); 0161 } 0162 0163 void CoordTest::testGoLineStart() 0164 { 0165 const Coord coord(Pos, LineIndex); 0166 Coord otherCoord; 0167 0168 // goLineStart(), same line 0169 otherCoord.setLine(coord.line()); 0170 otherCoord.goLineStart(coord); 0171 QCOMPARE(otherCoord, coord); 0172 // goLineStart(), another line 0173 otherCoord.goUp(); 0174 otherCoord.goLineStart(coord); 0175 QCOMPARE(otherCoord.pos(), 0); 0176 } 0177 0178 void CoordTest::testGoLineEnd() 0179 { 0180 const Coord coord(Pos, LineIndex); 0181 Coord otherCoord; 0182 0183 // goLineEnd(), same line 0184 otherCoord.setLine(coord.line()); 0185 otherCoord.goLineEnd(MaxPos, coord); 0186 QCOMPARE(otherCoord, coord); 0187 // goLineEnd(), another line 0188 otherCoord.goDown(); 0189 otherCoord.goLineEnd(MaxPos, coord); 0190 QCOMPARE(otherCoord.pos(), MaxPos); 0191 } 0192 0193 void CoordTest::testCompareOperator() 0194 { 0195 const Coord coord(Pos, LineIndex); 0196 Coord otherCoord(coord); 0197 0198 otherCoord.goRight(); 0199 QVERIFY(otherCoord > coord); 0200 QVERIFY(!(otherCoord < coord)); 0201 otherCoord.goLeft(2); 0202 QVERIFY(otherCoord < coord); 0203 QVERIFY(!(otherCoord > coord)); 0204 otherCoord.goRight(); 0205 QVERIFY(!(otherCoord > coord)); 0206 QVERIFY(!(otherCoord < coord)); 0207 } 0208 0209 void CoordTest::testIsBelowIsAbove() 0210 { 0211 const Coord coord(Pos, LineIndex); 0212 Coord otherCoord(coord); 0213 0214 otherCoord.goDown(); 0215 QVERIFY(otherCoord.isBelow(coord.line())); 0216 QVERIFY(!otherCoord.isAbove(coord.line())); 0217 otherCoord.goUp(2); 0218 QVERIFY(otherCoord.isAbove(coord.line())); 0219 QVERIFY(!otherCoord.isBelow(coord.line())); 0220 otherCoord.goDown(); 0221 QVERIFY(!otherCoord.isAbove(coord.line())); 0222 QVERIFY(!otherCoord.isBelow(coord.line())); 0223 } 0224 0225 void CoordTest::testIsLaterPriorInLineThan() 0226 { 0227 const Coord coord(Pos, LineIndex); 0228 Coord otherCoord(coord); 0229 0230 otherCoord.goRight(); 0231 QVERIFY(otherCoord.isLaterInLineThan(coord)); 0232 QVERIFY(!otherCoord.isPriorInLineThan(coord)); 0233 otherCoord.goLeft(2); 0234 QVERIFY(otherCoord.isPriorInLineThan(coord)); 0235 QVERIFY(!otherCoord.isLaterInLineThan(coord)); 0236 otherCoord.goRight(); 0237 QVERIFY(!otherCoord.isPriorInLineThan(coord)); 0238 QVERIFY(!otherCoord.isLaterInLineThan(coord)); 0239 } 0240 0241 void CoordTest::testIsBeforeLineStart() 0242 { 0243 Coord coord(1, LineIndex); 0244 0245 QVERIFY(coord.isBehindLineStart()); 0246 QVERIFY(coord.isValid()); 0247 coord.goLeft(); 0248 QVERIFY(!coord.isBehindLineStart()); 0249 QVERIFY(coord.isValid()); 0250 } 0251 0252 void CoordTest::testIsBeforeLineEnd() 0253 { 0254 Coord coord(MaxPos - 1, LineIndex); 0255 0256 QVERIFY(coord.isBeforeLineEnd(MaxPos)); 0257 QVERIFY(coord.isValid()); 0258 coord.goRight(); 0259 QVERIFY(!coord.isBeforeLineEnd(MaxPos)); 0260 QVERIFY(coord.isValid()); 0261 } 0262 0263 void CoordTest::testIndexNWidth() 0264 { 0265 Coord coord; 0266 coord.setByIndexNWidth(Index, LineWidth); 0267 QCOMPARE(coord.indexByLineWidth(LineWidth), Index); 0268 QVERIFY(coord.isValid()); 0269 } 0270 0271 } 0272 0273 QTEST_MAIN(Okteta::CoordTest) 0274 0275 #include "moc_coordtest.cpp"