1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
16 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ** In addition, as a special exception, Nokia gives you certain additional
26 ** rights. These rights are described in the Nokia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
32 **************************************************************************/
34 #include <utils/changeset.h>
36 #include <QtTest/QtTest>
38 //TESTED_COMPONENT=src/utils/changeset
40 class tst_ChangeSet : public QObject
57 void tst_ChangeSet::singleReplace()
61 QString test("abcdef");
62 QVERIFY(cs.replace(0, 2, "ghi"));
64 QCOMPARE(test, QLatin1String("ghicdef"));
68 QString test("abcdef");
69 QVERIFY(cs.replace(4, 6, "ghi"));
71 QCOMPARE(test, QLatin1String("abcdghi"));
75 QString test("abcdef");
76 QVERIFY(cs.replace(3, 3, "ghi"));
78 QCOMPARE(test, QLatin1String("abcghidef"));
82 QString test("abcdef");
83 QVERIFY(cs.replace(0, 6, ""));
85 QCOMPARE(test, QLatin1String(""));
89 QString test("abcdef");
90 QVERIFY(cs.replace(3, 13, "ghi"));
92 QCOMPARE(test, QLatin1String("abcghi"));
96 void tst_ChangeSet::singleMove()
100 QString test("abcdef");
101 QVERIFY(cs.move(0, 2, 4));
103 QCOMPARE(test, QLatin1String("cdabef"));
107 QString test("abcdef");
108 QVERIFY(cs.move(4, 6, 0));
110 QCOMPARE(test, QLatin1String("efabcd"));
114 QString test("abcdef");
115 QVERIFY(cs.move(3, 13, 0));
117 QCOMPARE(test, QLatin1String("defabc"));
121 QString test("abcdef");
122 QVERIFY(cs.move(3, 3, 0));
124 QCOMPARE(test, QLatin1String("abcdef"));
128 QString test("abcdef");
129 QVERIFY(cs.move(0, 1, 10));
131 // ### maybe this should expand the string or error?
132 QCOMPARE(test, QLatin1String("bcdef"));
136 void tst_ChangeSet::singleInsert()
140 QString test("abcdef");
141 QVERIFY(cs.insert(0, "ghi"));
143 QCOMPARE(test, QLatin1String("ghiabcdef"));
147 QString test("abcdef");
148 QVERIFY(cs.insert(6, "ghi"));
150 QCOMPARE(test, QLatin1String("abcdefghi"));
154 QString test("abcdef");
155 QVERIFY(cs.insert(3, ""));
157 QCOMPARE(test, QLatin1String("abcdef"));
161 QString test("abcdef");
162 QVERIFY(cs.insert(7, "g"));
164 // ### maybe this should expand the string or error?
165 QCOMPARE(test, QLatin1String("abcdef"));
169 void tst_ChangeSet::singleRemove()
173 QString test("abcdef");
174 QVERIFY(cs.remove(0, 1));
176 QCOMPARE(test, QLatin1String("bcdef"));
180 QString test("abcdef");
181 QVERIFY(cs.remove(3, 6));
183 QCOMPARE(test, QLatin1String("abc"));
187 QString test("abcdef");
188 QVERIFY(cs.remove(4, 14));
190 QCOMPARE(test, QLatin1String("abcd"));
194 QString test("abcdef");
195 QVERIFY(cs.remove(2, 2));
197 QCOMPARE(test, QLatin1String("abcdef"));
201 QString test("abcdef");
202 QVERIFY(cs.remove(7, 8));
204 QCOMPARE(test, QLatin1String("abcdef"));
208 void tst_ChangeSet::singleFlip()
212 QString test("abcdef");
213 QVERIFY(cs.flip(0, 2, 3, 6));
215 QCOMPARE(test, QLatin1String("defcab"));
219 QString test("abcdef");
220 QVERIFY(cs.flip(1, 3, 3, 4));
222 QCOMPARE(test, QLatin1String("adbcef"));
226 QString test("abcdef");
227 QVERIFY(cs.flip(3, 3, 4, 4));
229 QCOMPARE(test, QLatin1String("abcdef"));
233 QString test("abcdef");
234 QVERIFY(cs.flip(3, 3, 4, 5));
236 QCOMPARE(test, QLatin1String("abcedf"));
240 QString test("abcdef");
241 QVERIFY(cs.flip(0, 6, 6, 12));
243 QCOMPARE(test, QLatin1String("abcdef"));
247 QString test("abcdef");
248 QVERIFY(cs.flip(0, 6, 7, 10));
250 // ### maybe this should expand the string or error?
251 QCOMPARE(test, QLatin1String(""));
255 QCOMPARE(cs.flip(0, 3, 1, 4), false);
259 QCOMPARE(cs.flip(0, 3, 2, 5), false);
263 QVERIFY(cs.flip(0, 3, 0, 0));
264 QString test("abcdef");
266 QCOMPARE(test, QLatin1String("abcdef"));
270 QVERIFY(cs.flip(0, 0, 0, 3));
271 QString test("abcdef");
273 QCOMPARE(test, QLatin1String("abcdef"));
277 QVERIFY(cs.flip(0, 3, 3, 3));
278 QString test("abcdef");
280 QCOMPARE(test, QLatin1String("abcdef"));
284 void tst_ChangeSet::singleCopy()
288 QString test("abcdef");
289 QVERIFY(cs.copy(0, 2, 4));
291 QCOMPARE(test, QLatin1String("abcdabef"));
295 QString test("abcdef");
296 QVERIFY(cs.copy(1, 3, 3));
298 QCOMPARE(test, QLatin1String("abcbcdef"));
302 QString test("abcdef");
303 QVERIFY(cs.copy(3, 3, 4));
305 QCOMPARE(test, QLatin1String("abcdef"));
309 QString test("abcdef");
310 QVERIFY(cs.copy(0, 6, 6));
312 QCOMPARE(test, QLatin1String("abcdefabcdef"));
316 QString test("abcdef");
317 QVERIFY(cs.copy(0, 6, 7));
319 // ### maybe this should expand the string or error?
320 QCOMPARE(test, QLatin1String("abcdef"));
324 QCOMPARE(cs.copy(0, 3, 1), false);
328 QCOMPARE(cs.copy(0, 3, 2), false);
332 QVERIFY(cs.copy(0, 3, 0));
333 QString test("abcdef");
335 QCOMPARE(test, QLatin1String("abcabcdef"));
339 QVERIFY(cs.copy(0, 3, 3));
340 QString test("abcdef");
342 QCOMPARE(test, QLatin1String("abcabcdef"));
346 void tst_ChangeSet::doubleInsert()
350 QVERIFY(cs.insert(1, "01"));
351 QVERIFY(cs.insert(1, "234"));
352 QString test("abcdef");
354 QCOMPARE(test, QLatin1String("a01234bcdef"));
358 QVERIFY(cs.insert(1, "234"));
359 QVERIFY(cs.insert(1, "01"));
360 QString test("abcdef");
362 QCOMPARE(test, QLatin1String("a23401bcdef"));
366 QVERIFY(cs.insert(1, "01"));
367 QVERIFY(cs.remove(1, 2));
368 QVERIFY(cs.insert(2, "234"));
369 QString test("abcdef");
371 QCOMPARE(test, QLatin1String("a01234cdef"));
375 void tst_ChangeSet::conflicts()
379 QVERIFY(cs.move(1, 4, 5));
380 QCOMPARE(cs.replace(0, 2, "abc"), false);
384 QVERIFY(cs.move(1, 4, 5));
385 QCOMPARE(cs.replace(1, 4, "abc"), false);
389 QVERIFY(cs.move(1, 4, 5));
390 QCOMPARE(cs.replace(1, 2, "abc"), false);
394 QVERIFY(cs.move(1, 4, 5));
395 QCOMPARE(cs.replace(2, 2, "abc"), false);
399 QVERIFY(cs.move(1, 4, 5));
400 QCOMPARE(cs.replace(2, 3, "abc"), false);
404 QVERIFY(cs.move(1, 4, 5));
405 QCOMPARE(cs.replace(3, 3, "abc"), false);
409 QVERIFY(cs.move(1, 4, 5));
410 QCOMPARE(cs.replace(3, 4, "abc"), false);
414 QVERIFY(cs.move(1, 4, 5));
415 QCOMPARE(cs.replace(4, 6, "abc"), false);
420 QVERIFY(cs.move(1, 4, 5));
421 QVERIFY(cs.replace(0, 1, "bla"));
422 QString test("abcdef");
424 QCOMPARE(test, QLatin1String("blaebcdf"));
428 QVERIFY(cs.move(1, 4, 5));
429 QVERIFY(cs.replace(4, 5, "bla"));
430 QString test("abcdef");
432 QCOMPARE(test, QLatin1String("ablabcdf"));
436 QVERIFY(cs.move(1, 4, 5));
437 QVERIFY(cs.replace(5, 6, "bla"));
438 QString test("abcdef");
440 QCOMPARE(test, QLatin1String("aebcdbla"));
444 QTEST_MAIN(tst_ChangeSet)
446 #include "tst_changeset.moc"