File indexing completed on 2024-05-12 16:35:58
0001 /* This file is part of the KDE project 0002 Copyright 2010 Marijn Kruisselbrink <mkruisselbrink@kde.org> 0003 0004 This library is free software; you can redistribute it and/or 0005 modify it under the terms of the GNU Library General Public 0006 License as published by the Free Software Foundation; either 0007 version 2 of the License, or (at your option) any later version. 0008 0009 This library is distributed in the hope that it will be useful, 0010 but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0012 Library General Public License for more details. 0013 0014 You should have received a copy of the GNU Library General Public License 0015 along with this library; see the file COPYING.LIB. If not, write to 0016 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0017 Boston, MA 02110-1301, USA. 0018 */ 0019 #include "TestRowRepeatStorage.h" 0020 0021 #include <QVector> 0022 0023 #include <QTest> 0024 0025 #include "../RowRepeatStorage.h" 0026 #include "../calligra_sheets_limits.h" 0027 0028 using namespace Calligra::Sheets; 0029 0030 namespace { 0031 static const int kCutOff = 65535; 0032 static const int kStepSize = 1238; 0033 } 0034 0035 void TestRowRepeatStorage::testEmptyStorage() 0036 { 0037 RowRepeatStorage s; 0038 for (int i = 1; i <= KS_rowMax; i++) { 0039 QCOMPARE(s.rowRepeat(i), 1); 0040 QCOMPARE(s.firstIdenticalRow(i), i); 0041 if (i > kCutOff) i += kStepSize; 0042 } 0043 } 0044 0045 void TestRowRepeatStorage::testSimpleSetRowRepeat() 0046 { 0047 // test simple non-overlapping ranges 0048 RowRepeatStorage s; 0049 s.setRowRepeat(10, 5); 0050 for (int i = 1; i <= KS_rowMax; i++) { 0051 if (i >= 10 && i < 15) { 0052 QCOMPARE(s.rowRepeat(i), 5); 0053 QCOMPARE(s.firstIdenticalRow(i), 10); 0054 } else { 0055 QCOMPARE(s.rowRepeat(i), 1); 0056 QCOMPARE(s.firstIdenticalRow(i), i); 0057 } 0058 if (i > kCutOff) i += kStepSize; 0059 } 0060 s.setRowRepeat(44, 7); 0061 for (int i = 1; i <= KS_rowMax; i++) { 0062 if (i >= 10 && i < 15) { 0063 QCOMPARE(s.rowRepeat(i), 5); 0064 QCOMPARE(s.firstIdenticalRow(i), 10); 0065 } else if (i >= 44 && i < 51) { 0066 QCOMPARE(s.rowRepeat(i), 7); 0067 QCOMPARE(s.firstIdenticalRow(i), 44); 0068 } else { 0069 QCOMPARE(s.rowRepeat(i), 1); 0070 QCOMPARE(s.firstIdenticalRow(i), i); 0071 } 0072 if (i > kCutOff) i += kStepSize; 0073 } 0074 s.setRowRepeat(15, 4); 0075 for (int i = 1; i <= KS_rowMax; i++) { 0076 if (i >= 10 && i < 15) { 0077 QCOMPARE(s.rowRepeat(i), 5); 0078 QCOMPARE(s.firstIdenticalRow(i), 10); 0079 } else if (i >= 15 && i < 19) { 0080 QCOMPARE(s.rowRepeat(i), 4); 0081 QCOMPARE(s.firstIdenticalRow(i), 15); 0082 } else if (i >= 44 && i < 51) { 0083 QCOMPARE(s.rowRepeat(i), 7); 0084 QCOMPARE(s.firstIdenticalRow(i), 44); 0085 } else { 0086 QCOMPARE(s.rowRepeat(i), 1); 0087 QCOMPARE(s.firstIdenticalRow(i), i); 0088 } 0089 if (i > kCutOff) i += kStepSize; 0090 } 0091 } 0092 0093 void TestRowRepeatStorage::testOverlappingRanges_data() 0094 { 0095 QTest::addColumn<int>("firststart"); 0096 QTest::addColumn<int>("firstcount"); 0097 QTest::addColumn<int>("secondstart"); 0098 QTest::addColumn<int>("secondcount"); 0099 0100 QTest::newRow("non overlapping") << 5 << 5 << 10 << 5; 0101 QTest::newRow("overlap end 1") << 5 << 5 << 9 << 5; 0102 QTest::newRow("overlap end 2") << 5 << 5 << 8 << 5; 0103 QTest::newRow("overlap start 1") << 10 << 5 << 6 << 5; 0104 QTest::newRow("overlap start 2") << 10 << 5 << 7 << 5; 0105 QTest::newRow("overlap middle") << 5 << 10 << 7 << 5; 0106 QTest::newRow("fully cover") << 7 << 5 << 5 << 10; 0107 } 0108 0109 void TestRowRepeatStorage::testOverlappingRanges() 0110 { 0111 RowRepeatStorage s; 0112 0113 QFETCH(int, firststart); 0114 QFETCH(int, firstcount); 0115 QFETCH(int, secondstart); 0116 QFETCH(int, secondcount); 0117 0118 s.setRowRepeat(firststart, firstcount); 0119 s.setRowRepeat(secondstart, secondcount); 0120 0121 for (int i = 1; i <= KS_rowMax; i++) { 0122 if (i >= secondstart && i < secondstart + secondcount) { 0123 QCOMPARE(s.rowRepeat(i), secondcount); 0124 QCOMPARE(s.firstIdenticalRow(i), secondstart); 0125 } else if (i >= firststart && i < firststart + firstcount) { 0126 if (i < secondstart) { 0127 QCOMPARE(s.rowRepeat(i), qMin(firstcount, secondstart - firststart)); 0128 QCOMPARE(s.firstIdenticalRow(i), firststart); 0129 } else { 0130 QCOMPARE(s.rowRepeat(i), qMin(firstcount, firststart + firstcount - secondstart - secondcount)); 0131 QCOMPARE(s.firstIdenticalRow(i), qMax(firststart, secondstart + secondcount)); 0132 } 0133 } else { 0134 QCOMPARE(s.rowRepeat(i), 1); 0135 QCOMPARE(s.firstIdenticalRow(i), i); 0136 } 0137 if (i > kCutOff) i += kStepSize; 0138 } 0139 } 0140 0141 void TestRowRepeatStorage::testComplexSetRowRepeat() 0142 { 0143 RowRepeatStorage s; 0144 0145 s.setRowRepeat(1, 1000); 0146 s.setRowRepeat(5, 100); 0147 s.setRowRepeat(10, 10); 0148 s.setRowRepeat(90, 50); 0149 s.setRowRepeat(15, 100); 0150 0151 for (int i = 1; i <= KS_rowMax; i++) { 0152 if (i < 5) { 0153 QCOMPARE(s.rowRepeat(i), 4); 0154 QCOMPARE(s.firstIdenticalRow(i), 1); 0155 } else if (i < 10) { 0156 QCOMPARE(s.rowRepeat(i), 5); 0157 QCOMPARE(s.firstIdenticalRow(i), 5); 0158 } else if (i < 15) { 0159 QCOMPARE(s.rowRepeat(i), 5); 0160 QCOMPARE(s.firstIdenticalRow(i), 10); 0161 } else if (i < 115) { 0162 QCOMPARE(s.rowRepeat(i), 100); 0163 QCOMPARE(s.firstIdenticalRow(i), 15); 0164 } else if (i < 140) { 0165 QCOMPARE(s.rowRepeat(i), 25); 0166 QCOMPARE(s.firstIdenticalRow(i), 115); 0167 } else if (i <= 1000) { 0168 QCOMPARE(s.rowRepeat(i), 861); 0169 QCOMPARE(s.firstIdenticalRow(i), 140); 0170 } else { 0171 QCOMPARE(s.rowRepeat(i), 1); 0172 QCOMPARE(s.firstIdenticalRow(i), i); 0173 } 0174 if (i > kCutOff) i += kStepSize; 0175 } 0176 } 0177 0178 void TestRowRepeatStorage::testInsertRowsEmpty() 0179 { 0180 RowRepeatStorage s; 0181 s.insertRows(10, 5); 0182 0183 for (int i = 1; i <= KS_rowMax; i++) { 0184 if (i >= 10 && i < 15) { 0185 QCOMPARE(s.rowRepeat(i), 5); 0186 QCOMPARE(s.firstIdenticalRow(i), 10); 0187 } else { 0188 QCOMPARE(s.rowRepeat(i), 1); 0189 QCOMPARE(s.firstIdenticalRow(i), i); 0190 } 0191 if (i > kCutOff) i += kStepSize; 0192 } 0193 } 0194 0195 void TestRowRepeatStorage::testInsertRowsBetween() 0196 { 0197 RowRepeatStorage s; 0198 0199 s.setRowRepeat(5, 10); 0200 s.setRowRepeat(40, 10); 0201 s.insertRows(20, 10); 0202 0203 for (int i = 1; i <= KS_rowMax; i++) { 0204 if (i < 5 || i >= 60) { 0205 QCOMPARE(s.rowRepeat(i), 1); 0206 QCOMPARE(s.firstIdenticalRow(i), i); 0207 } else if (i < 15) { 0208 QCOMPARE(s.rowRepeat(i), 10); 0209 QCOMPARE(s.firstIdenticalRow(i), 5); 0210 } else if (i < 20) { 0211 QCOMPARE(s.rowRepeat(i), 1); 0212 QCOMPARE(s.firstIdenticalRow(i), i); 0213 } else if (i < 30) { 0214 QCOMPARE(s.rowRepeat(i), 10); 0215 QCOMPARE(s.firstIdenticalRow(i), 20); 0216 } else if (i < 50) { 0217 QCOMPARE(s.rowRepeat(i), 1); 0218 QCOMPARE(s.firstIdenticalRow(i), i); 0219 } else if (i < 60) { 0220 QCOMPARE(s.rowRepeat(i), 10); 0221 QCOMPARE(s.firstIdenticalRow(i), 50); 0222 } 0223 if (i > kCutOff) i += kStepSize; 0224 } 0225 } 0226 0227 void TestRowRepeatStorage::testInsertRowsMiddle() 0228 { 0229 RowRepeatStorage s; 0230 s.setRowRepeat(10, 20); 0231 s.insertRows(20, 7); 0232 0233 for (int i = 1; i <= KS_rowMax; i++) { 0234 if (i < 10 || i >= 37) { 0235 QCOMPARE(s.rowRepeat(i), 1); 0236 QCOMPARE(s.firstIdenticalRow(i), i); 0237 } else if (i < 20) { 0238 QCOMPARE(s.rowRepeat(i), 10); 0239 QCOMPARE(s.firstIdenticalRow(i), 10); 0240 } else if (i < 27) { 0241 QCOMPARE(s.rowRepeat(i), 7); 0242 QCOMPARE(s.firstIdenticalRow(i), 20); 0243 } else if (i < 37) { 0244 QCOMPARE(s.rowRepeat(i), 10); 0245 QCOMPARE(s.firstIdenticalRow(i), 27); 0246 } 0247 if (i > kCutOff) i += kStepSize; 0248 } 0249 } 0250 0251 void TestRowRepeatStorage::testRemoveRowsEmpty() 0252 { 0253 RowRepeatStorage s; 0254 s.removeRows(10, 20); 0255 0256 for (int i = 1; i <= KS_rowMax; i++) { 0257 QCOMPARE(s.rowRepeat(i), 1); 0258 QCOMPARE(s.firstIdenticalRow(i), i); 0259 if (i > kCutOff) i += kStepSize; 0260 } 0261 } 0262 0263 void TestRowRepeatStorage::testRemoveRowsBetween() 0264 { 0265 RowRepeatStorage s; 0266 s.setRowRepeat(5, 10); 0267 s.setRowRepeat(50, 20); 0268 s.removeRows(25, 5); 0269 0270 for (int i = 0; i < KS_rowMax; i++) { 0271 if (i < 5 || i >= 65) { 0272 QCOMPARE(s.rowRepeat(i), 1); 0273 QCOMPARE(s.firstIdenticalRow(i), i); 0274 } else if (i < 15) { 0275 QCOMPARE(s.rowRepeat(i), 10); 0276 QCOMPARE(s.firstIdenticalRow(i), 5); 0277 } else if (i < 45) { 0278 QCOMPARE(s.rowRepeat(i), 1); 0279 QCOMPARE(s.firstIdenticalRow(i), i); 0280 } else if (i < 65) { 0281 QCOMPARE(s.rowRepeat(i), 20); 0282 QCOMPARE(s.firstIdenticalRow(i), 45); 0283 } 0284 if (i > kCutOff) i += kStepSize; 0285 } 0286 } 0287 0288 void TestRowRepeatStorage::testRemoveRowsOverlap() 0289 { 0290 RowRepeatStorage s; 0291 s.setRowRepeat(5, 15); 0292 s.setRowRepeat(30, 10); 0293 s.setRowRepeat(12, 4); 0294 s.removeRows(10, 22); 0295 0296 for (int i = 0; i < KS_rowMax; i++) { 0297 if (i < 5 || i >= 18) { 0298 QCOMPARE(s.rowRepeat(i), 1); 0299 QCOMPARE(s.firstIdenticalRow(i), i); 0300 } else if (i < 10) { 0301 QCOMPARE(s.rowRepeat(i), 5); 0302 QCOMPARE(s.firstIdenticalRow(i), 5); 0303 } else if (i < 18) { 0304 QCOMPARE(s.rowRepeat(i), 8); 0305 QCOMPARE(s.firstIdenticalRow(i), 10); 0306 } 0307 if (i > kCutOff) i += kStepSize; 0308 } 0309 } 0310 0311 void TestRowRepeatStorage::testInsertShiftDown1() 0312 { 0313 // entire rect inside one row-repeat, with a smaller and a larger row repeat after it 0314 RowRepeatStorage s; 0315 s.setRowRepeat(10, 20); 0316 s.setRowRepeat(100, 5); 0317 s.setRowRepeat(200, 50); 0318 s.insertShiftDown(QRect(5, 15, 10, 10)); 0319 0320 for (int i = 1; i <= KS_rowMax; i++) { 0321 if (i < 10) { 0322 QCOMPARE(s.rowRepeat(i), 1); 0323 QCOMPARE(s.firstIdenticalRow(i), i); 0324 } else if (i < 15) { 0325 QCOMPARE(s.rowRepeat(i), 5); 0326 QCOMPARE(s.firstIdenticalRow(i), 10); 0327 } else if (i < 25) { 0328 QCOMPARE(s.rowRepeat(i), 10); 0329 QCOMPARE(s.firstIdenticalRow(i), 15); 0330 } else if (i < 30) { 0331 QCOMPARE(s.rowRepeat(i), 5); 0332 QCOMPARE(s.firstIdenticalRow(i), 25); 0333 } else if (i < 210) { 0334 QCOMPARE(s.rowRepeat(i), 1); 0335 QCOMPARE(s.firstIdenticalRow(i), i); 0336 } else if (i < 250) { 0337 QCOMPARE(s.rowRepeat(i), 40); 0338 QCOMPARE(s.firstIdenticalRow(i), 210); 0339 } else { 0340 QCOMPARE(s.rowRepeat(i), 1); 0341 QCOMPARE(s.firstIdenticalRow(i), i); 0342 } 0343 if (i > kCutOff) i += kStepSize; 0344 } 0345 } 0346 0347 void TestRowRepeatStorage::testInsertShiftDown2() 0348 { 0349 // rect overlapping the end of a row-repeat, with a smaller and a larger row repeat after it 0350 RowRepeatStorage s; 0351 s.setRowRepeat(10, 20); 0352 s.setRowRepeat(100, 5); 0353 s.setRowRepeat(200, 50); 0354 s.insertShiftDown(QRect(5, 25, 10, 10)); 0355 0356 for (int i = 1; i <= KS_rowMax; i++) { 0357 if (i < 10) { 0358 QCOMPARE(s.rowRepeat(i), 1); 0359 QCOMPARE(s.firstIdenticalRow(i), i); 0360 } else if (i < 25) { 0361 QCOMPARE(s.rowRepeat(i), 15); 0362 QCOMPARE(s.firstIdenticalRow(i), 10); 0363 } else if (i < 30) { 0364 QCOMPARE(s.rowRepeat(i), 5); 0365 QCOMPARE(s.firstIdenticalRow(i), 25); 0366 } else if (i < 210) { 0367 QCOMPARE(s.rowRepeat(i), 1); 0368 QCOMPARE(s.firstIdenticalRow(i), i); 0369 } else if (i < 250) { 0370 QCOMPARE(s.rowRepeat(i), 40); 0371 QCOMPARE(s.firstIdenticalRow(i), 210); 0372 } else { 0373 QCOMPARE(s.rowRepeat(i), 1); 0374 QCOMPARE(s.firstIdenticalRow(i), i); 0375 } 0376 if (i > kCutOff) i += kStepSize; 0377 } 0378 } 0379 0380 void TestRowRepeatStorage::testInsertShiftDown3() 0381 { 0382 // rect overlapping the start of a row-repeat, with a smaller and a larger row repeat after it 0383 RowRepeatStorage s; 0384 s.setRowRepeat(10, 20); 0385 s.setRowRepeat(100, 5); 0386 s.setRowRepeat(200, 50); 0387 s.insertShiftDown(QRect(5, 5, 10, 10)); 0388 0389 for (int i = 1; i <= KS_rowMax; i++) { 0390 if (i < 10) { 0391 QCOMPARE(s.rowRepeat(i), 1); 0392 QCOMPARE(s.firstIdenticalRow(i), i); 0393 } else if (i < 15) { 0394 QCOMPARE(s.rowRepeat(i), 5); 0395 QCOMPARE(s.firstIdenticalRow(i), 10); 0396 } else if (i < 20) { 0397 QCOMPARE(s.rowRepeat(i), 1); 0398 QCOMPARE(s.firstIdenticalRow(i), i); 0399 } else if (i < 30) { 0400 QCOMPARE(s.rowRepeat(i), 10); 0401 QCOMPARE(s.firstIdenticalRow(i), 20); 0402 } else if (i < 210) { 0403 QCOMPARE(s.rowRepeat(i), 1); 0404 QCOMPARE(s.firstIdenticalRow(i), i); 0405 } else if (i < 250) { 0406 QCOMPARE(s.rowRepeat(i), 40); 0407 QCOMPARE(s.firstIdenticalRow(i), 210); 0408 } else { 0409 QCOMPARE(s.rowRepeat(i), 1); 0410 QCOMPARE(s.firstIdenticalRow(i), i); 0411 } 0412 if (i > kCutOff) i += kStepSize; 0413 } 0414 } 0415 0416 void TestRowRepeatStorage::testInsertShiftDown4() 0417 { 0418 // rect overlapping the start and end of a row-repeat, with a smaller and a larger row repeat after it 0419 RowRepeatStorage s; 0420 s.setRowRepeat(10, 20); 0421 s.setRowRepeat(35, 30); 0422 s.setRowRepeat(100, 5); 0423 s.setRowRepeat(200, 50); 0424 s.insertShiftDown(QRect(5, 15, 10, 25)); 0425 0426 for (int i = 1; i <= KS_rowMax; i++) { 0427 if (i < 10) { 0428 QCOMPARE(s.rowRepeat(i), 1); 0429 QCOMPARE(s.firstIdenticalRow(i), i); 0430 } else if (i < 15) { 0431 QCOMPARE(s.rowRepeat(i), 5); 0432 QCOMPARE(s.firstIdenticalRow(i), 10); 0433 } else if (i < 30) { 0434 QCOMPARE(s.rowRepeat(i), 15); 0435 QCOMPARE(s.firstIdenticalRow(i), 15); 0436 } else if (i < 35) { 0437 QCOMPARE(s.rowRepeat(i), 1); 0438 QCOMPARE(s.firstIdenticalRow(i), i); 0439 } else if (i < 40) { 0440 QCOMPARE(s.rowRepeat(i), 5); 0441 QCOMPARE(s.firstIdenticalRow(i), 35); 0442 } else if (i < 55) { 0443 QCOMPARE(s.rowRepeat(i), 15); 0444 QCOMPARE(s.firstIdenticalRow(i), 40); 0445 } else if (i < 60) { 0446 QCOMPARE(s.rowRepeat(i), 1); 0447 QCOMPARE(s.firstIdenticalRow(i), i); 0448 } else if (i < 65) { 0449 QCOMPARE(s.rowRepeat(i), 5); 0450 QCOMPARE(s.firstIdenticalRow(i), 60); 0451 } else if (i < 225) { 0452 QCOMPARE(s.rowRepeat(i), 1); 0453 QCOMPARE(s.firstIdenticalRow(i), i); 0454 } else if (i < 250) { 0455 QCOMPARE(s.rowRepeat(i), 25); 0456 QCOMPARE(s.firstIdenticalRow(i), 225); 0457 } else { 0458 QCOMPARE(s.rowRepeat(i), 1); 0459 QCOMPARE(s.firstIdenticalRow(i), i); 0460 } 0461 if (i > kCutOff) i += kStepSize; 0462 } 0463 } 0464 0465 void TestRowRepeatStorage::testRemoveShiftUp1() 0466 { 0467 // entire rect inside one row-repeat, with a smaller and a larger row repeat after it 0468 RowRepeatStorage s; 0469 s.setRowRepeat(10, 20); 0470 s.setRowRepeat(100, 5); 0471 s.setRowRepeat(200, 50); 0472 s.removeShiftUp(QRect(5, 15, 10, 10)); 0473 0474 for (int i = 1; i <= KS_rowMax; i++) { 0475 if (i < 10) { 0476 QCOMPARE(s.rowRepeat(i), 1); 0477 QCOMPARE(s.firstIdenticalRow(i), i); 0478 } else if (i < 15) { 0479 QCOMPARE(s.rowRepeat(i), 5); 0480 QCOMPARE(s.firstIdenticalRow(i), 10); 0481 } else if (i < 20) { 0482 QCOMPARE(s.rowRepeat(i), 5); 0483 QCOMPARE(s.firstIdenticalRow(i), 15); 0484 } else if (i < 200) { 0485 QCOMPARE(s.rowRepeat(i), 1); 0486 QCOMPARE(s.firstIdenticalRow(i), i); 0487 } else if (i < 240) { 0488 QCOMPARE(s.rowRepeat(i), 40); 0489 QCOMPARE(s.firstIdenticalRow(i), 200); 0490 } else { 0491 QCOMPARE(s.rowRepeat(i), 1); 0492 QCOMPARE(s.firstIdenticalRow(i), i); 0493 } 0494 if (i > kCutOff) i += kStepSize; 0495 } 0496 } 0497 0498 void TestRowRepeatStorage::testRemoveShiftUp2() 0499 { 0500 // rect overlapping the end of a row-repeat, with a smaller and a larger row repeat after it 0501 RowRepeatStorage s; 0502 s.setRowRepeat(10, 20); 0503 s.setRowRepeat(100, 5); 0504 s.setRowRepeat(200, 50); 0505 s.removeShiftUp(QRect(5, 25, 10, 10)); 0506 0507 for (int i = 1; i <= KS_rowMax; i++) { 0508 if (i < 10) { 0509 QCOMPARE(s.rowRepeat(i), 1); 0510 QCOMPARE(s.firstIdenticalRow(i), i); 0511 } else if (i < 25) { 0512 QCOMPARE(s.rowRepeat(i), 15); 0513 QCOMPARE(s.firstIdenticalRow(i), 10); 0514 } else if (i < 200) { 0515 QCOMPARE(s.rowRepeat(i), 1); 0516 QCOMPARE(s.firstIdenticalRow(i), i); 0517 } else if (i < 240) { 0518 QCOMPARE(s.rowRepeat(i), 40); 0519 QCOMPARE(s.firstIdenticalRow(i), 200); 0520 } else { 0521 QCOMPARE(s.rowRepeat(i), 1); 0522 QCOMPARE(s.firstIdenticalRow(i), i); 0523 } 0524 if (i > kCutOff) i += kStepSize; 0525 } 0526 } 0527 0528 void TestRowRepeatStorage::testRemoveShiftUp3() 0529 { 0530 // rect overlapping the start of a row-repeat, with a smaller and a larger row repeat after it 0531 RowRepeatStorage s; 0532 s.setRowRepeat(10, 20); 0533 s.setRowRepeat(100, 5); 0534 s.setRowRepeat(200, 50); 0535 s.removeShiftUp(QRect(5, 5, 10, 10)); 0536 0537 for (int i = 1; i <= KS_rowMax; i++) { 0538 if (i < 10) { 0539 QCOMPARE(s.rowRepeat(i), 1); 0540 QCOMPARE(s.firstIdenticalRow(i), i); 0541 } else if (i < 20) { 0542 QCOMPARE(s.rowRepeat(i), 10); 0543 QCOMPARE(s.firstIdenticalRow(i), 10); 0544 } else if (i < 200) { 0545 QCOMPARE(s.rowRepeat(i), 1); 0546 QCOMPARE(s.firstIdenticalRow(i), i); 0547 } else if (i < 240) { 0548 QCOMPARE(s.rowRepeat(i), 40); 0549 QCOMPARE(s.firstIdenticalRow(i), 200); 0550 } else { 0551 QCOMPARE(s.rowRepeat(i), 1); 0552 QCOMPARE(s.firstIdenticalRow(i), i); 0553 } 0554 if (i > kCutOff) i += kStepSize; 0555 } 0556 } 0557 0558 void TestRowRepeatStorage::testRemoveShiftUp4() 0559 { 0560 // rect overlapping the start and end of a row-repeat, with a smaller and a larger row repeat after it 0561 RowRepeatStorage s; 0562 s.setRowRepeat(10, 20); 0563 s.setRowRepeat(35, 30); 0564 s.setRowRepeat(100, 5); 0565 s.setRowRepeat(200, 50); 0566 s.removeShiftUp(QRect(5, 15, 10, 25)); 0567 0568 for (int i = 1; i <= KS_rowMax; i++) { 0569 if (i < 10) { 0570 QCOMPARE(s.rowRepeat(i), 1); 0571 QCOMPARE(s.firstIdenticalRow(i), i); 0572 } else if (i < 15) { 0573 QCOMPARE(s.rowRepeat(i), 5); 0574 QCOMPARE(s.firstIdenticalRow(i), 10); 0575 } else if (i < 30) { 0576 QCOMPARE(s.rowRepeat(i), 15); 0577 QCOMPARE(s.firstIdenticalRow(i), 15); 0578 } else if (i < 35) { 0579 QCOMPARE(s.rowRepeat(i), 1); 0580 QCOMPARE(s.firstIdenticalRow(i), i); 0581 } else if (i < 40) { 0582 QCOMPARE(s.rowRepeat(i), 5); 0583 QCOMPARE(s.firstIdenticalRow(i), 35); 0584 } else if (i < 200) { 0585 QCOMPARE(s.rowRepeat(i), 1); 0586 QCOMPARE(s.firstIdenticalRow(i), i); 0587 } else if (i < 225) { 0588 QCOMPARE(s.rowRepeat(i), 25); 0589 QCOMPARE(s.firstIdenticalRow(i), 200); 0590 } else { 0591 QCOMPARE(s.rowRepeat(i), 1); 0592 QCOMPARE(s.firstIdenticalRow(i), i); 0593 } 0594 if (i > kCutOff) i += kStepSize; 0595 } 0596 } 0597 0598 void TestRowRepeatStorage::testInsertShiftRight() 0599 { 0600 RowRepeatStorage s; 0601 s.setRowRepeat(5, 10); 0602 s.setRowRepeat(20, 10); 0603 s.setRowRepeat(35, 10); 0604 s.insertShiftRight(QRect(5, 10, 10, 30)); 0605 0606 for (int i = 1; i <= KS_rowMax; i++) { 0607 if (i < 5) { 0608 QCOMPARE(s.rowRepeat(i), 1); 0609 QCOMPARE(s.firstIdenticalRow(i), i); 0610 } else if (i < 10) { 0611 QCOMPARE(s.rowRepeat(i), 5); 0612 QCOMPARE(s.firstIdenticalRow(i), 5); 0613 } else if (i < 15) { 0614 QCOMPARE(s.rowRepeat(i), 5); 0615 QCOMPARE(s.firstIdenticalRow(i), 10); 0616 } else if (i < 20) { 0617 QCOMPARE(s.rowRepeat(i), 1); 0618 QCOMPARE(s.firstIdenticalRow(i), i); 0619 } else if (i < 30) { 0620 QCOMPARE(s.rowRepeat(i), 10); 0621 QCOMPARE(s.firstIdenticalRow(i), 20); 0622 } else if (i < 35) { 0623 QCOMPARE(s.rowRepeat(i), 1); 0624 QCOMPARE(s.firstIdenticalRow(i), i); 0625 } else if (i < 40) { 0626 QCOMPARE(s.rowRepeat(i), 5); 0627 QCOMPARE(s.firstIdenticalRow(i), 35); 0628 } else if (i < 45) { 0629 QCOMPARE(s.rowRepeat(i), 5); 0630 QCOMPARE(s.firstIdenticalRow(i), 40); 0631 } else { 0632 QCOMPARE(s.rowRepeat(i), 1); 0633 QCOMPARE(s.firstIdenticalRow(i), i); 0634 } 0635 if (i > kCutOff) i += kStepSize; 0636 } 0637 } 0638 0639 void TestRowRepeatStorage::testRemoveShiftLeft() 0640 { 0641 RowRepeatStorage s; 0642 s.setRowRepeat(5, 10); 0643 s.setRowRepeat(20, 10); 0644 s.setRowRepeat(35, 10); 0645 s.removeShiftLeft(QRect(5, 10, 10, 30)); 0646 0647 for (int i = 1; i <= KS_rowMax; i++) { 0648 if (i < 5) { 0649 QCOMPARE(s.rowRepeat(i), 1); 0650 QCOMPARE(s.firstIdenticalRow(i), i); 0651 } else if (i < 10) { 0652 QCOMPARE(s.rowRepeat(i), 5); 0653 QCOMPARE(s.firstIdenticalRow(i), 5); 0654 } else if (i < 15) { 0655 QCOMPARE(s.rowRepeat(i), 5); 0656 QCOMPARE(s.firstIdenticalRow(i), 10); 0657 } else if (i < 20) { 0658 QCOMPARE(s.rowRepeat(i), 1); 0659 QCOMPARE(s.firstIdenticalRow(i), i); 0660 } else if (i < 30) { 0661 QCOMPARE(s.rowRepeat(i), 10); 0662 QCOMPARE(s.firstIdenticalRow(i), 20); 0663 } else if (i < 35) { 0664 QCOMPARE(s.rowRepeat(i), 1); 0665 QCOMPARE(s.firstIdenticalRow(i), i); 0666 } else if (i < 40) { 0667 QCOMPARE(s.rowRepeat(i), 5); 0668 QCOMPARE(s.firstIdenticalRow(i), 35); 0669 } else if (i < 45) { 0670 QCOMPARE(s.rowRepeat(i), 5); 0671 QCOMPARE(s.firstIdenticalRow(i), 40); 0672 } else { 0673 QCOMPARE(s.rowRepeat(i), 1); 0674 QCOMPARE(s.firstIdenticalRow(i), i); 0675 } 0676 if (i > kCutOff) i += kStepSize; 0677 } 0678 } 0679 0680 QTEST_GUILESS_MAIN(TestRowRepeatStorage)