void qceEqual(const QDocumentCursor& c, const QDocumentCursor& expected, const QString& message){ QEQUAL2(c.hasSelection(),expected.hasSelection(), " got-total: "+cur2str(c)+" expected-total: "+cur2str(expected)+" more: "+message); QEQUAL2(c.anchorLineNumber(),expected.anchorLineNumber(), " got-total: "+cur2str(c)+" expected-total: "+cur2str(expected)+" more: "+message); QEQUAL2(c.anchorColumnNumber(),expected.anchorColumnNumber(), " got-total: "+cur2str(c)+" expected-total: "+cur2str(expected)+" more: "+message); QEQUAL2(c.lineNumber(),expected.lineNumber(), " got-total: "+cur2str(c)+" expected-total: "+cur2str(expected)+" more: "+message); QEQUAL2(c.columnNumber(),expected.columnNumber(), " got-total: "+cur2str(c)+" expected-total: "+cur2str(expected)+" more: "+message); }
//checks if load/saving preserves encoding and line endings void QEditorTest::loadSave(){ QFETCH(QString, outCodecName); QFETCH(QString, outLineEnding); QFETCH(bool, autodetect); QTextCodec* outCodec=QTextCodec::codecForName(qPrintable(outCodecName)); if (outCodecName=="latin1") outCodec = defaultCodec; if (!allTests) { qDebug("skipped load save test"); return; } const QString testText = QString::fromLatin1("hallo\n\xE4\xF6\xFC\n"); QString testTextWithLineEndings=testText; testTextWithLineEndings.replace("\n",outLineEnding); QTemporaryFile tf;//uncomment if you need to look at the files &tf=*(new QTemporaryFile); tf.open(); QString tfn=tf.fileName(); tf.write(outCodec->fromUnicode(testTextWithLineEndings)); tf.close(); //Load editor->setFileCodec(QTextCodec::codecForName("iso-8859-5")); editor->load(tfn,autodetect?0:outCodec); editor->document()->setLineEnding(editor->document()->originalLineEnding()); //TODO: find out why this line is only needed iff the editor passed by the testmanager is used and not if a new QEditor(0) is created QEQUAL2(editor->document()->text(),testTextWithLineEndings,QString("File: %1 Got file codec: %2 ").arg(tfn).arg(editor->getFileCodec()?QString::fromAscii(editor->getFileCodec()->name()):"<null>")); QVERIFY2(editor->getFileCodec()==outCodec,qPrintable(QString("wrong encoding: got %1 wanted %2 by the sheriff %3").arg(QString::fromAscii(editor->getFileCodec()->name())).arg(QString::fromAscii(outCodec->name())).arg(autodetect))); QEQUAL(editor->document()->lineEndingString(),outLineEnding); //Save editor->setText(editor->document()->text()+"Save test", false); editor->save(); tf.open(); QString writtenText=outCodec->toUnicode( tf.readAll()); tf.close(); QEQUAL2(writtenText, testTextWithLineEndings+"Save test", "file text check, file:"+tfn); QVERIFY2(writtenText.contains(outLineEnding), qPrintable("file don't contain right line ending, file"+tfn)); editor->setFileName(""); //reset filename so it won't get panically if the file is deleted editor->document()->setLineEnding(QDocument::Conservative); //reset line ending so we won't screw up the other tests }
void QDocumentCursorTest::bidiMoving(){ QFETCH(QString, text); QFETCH(int, line); QFETCH(int, column); QFETCH(int, dir); QFETCH(int, movement); QFETCH(int, newLine); QFETCH(int, newColumn); #if QT_VERSION >= 0x040800 doc->setText(text,false); for (int i=0;i<doc->lineCount();i++) doc->line(i).handle()->layout(i); QDocumentCursor c(doc, line, column); c.movePosition(movement, (QDocumentCursor::MoveOperation)dir); QEQUAL2(c.lineNumber(), newLine, "line" ); QEQUAL2(c.columnNumber(), newColumn, "column" ); #endif }
//must return void to be able to use QEQUAL,... void getHighlightedSelectionIntern(QEditor* ed, int &minLine, int& minCol, int& maxLine, int& maxCol, const QString& message){ int f=QDocument::formatFactory()->id("selection"); minLine=-1; maxLine=-1; int minRight = -1; for (int i=0;i<ed->document()->lines();i++){ QList<QFormatRange> overlays= ed->document()->line(i).getOverlays(f); if (overlays.size()==0) continue; QEQUAL2(overlays.size(),1,"multiple selection highlighted on the same line"+message); minLine=i; minCol=ed->document()->line(i).length(); int frLength=0; foreach (const QFormatRange& fr, overlays) if (fr.offset<minCol) { minCol=fr.offset; frLength=fr.length; } minRight=minCol+frLength; break; } if (minLine==-1) return; int maxLeft=-1; for (int i=ed->document()->lines()-1;i>=0;i--){ QList<QFormatRange> overlays= ed->document()->line(i).getOverlays(f); if (overlays.size()==0) continue; QEQUAL2(overlays.size(),1,"multiple selection highlighted on the same line"+message); maxLine=i; maxCol=0; int frOffset=0; foreach (const QFormatRange& fr, overlays) if (fr.offset+fr.length>maxCol) { maxCol=fr.offset+fr.length; frOffset=fr.offset; } maxLeft=frOffset; break; } if (maxLine==-1) return; if (minLine!=maxLine) { QEQUAL2(maxLeft,0,"highlighted selection starts too late in last line"+message); QEQUAL2(minRight,ed->document()->line(minLine).length(),"highlighted selection too short in first line"+message); } for (int i = minLine+1;i<maxLine;i++){ QList<QFormatRange> overlays= ed->document()->line(i).getOverlays(f); QSVERIFY2(overlays.size()<=1,"multiple selection highlighted on the same line"+message); QEQUAL2(overlays.size(),1,QString("no selection highlighted in line %1: %2").arg(i).arg(message)); QEQUAL2(overlays[0].offset,0,"selection highlighting start not at offset 0: "+message); QEQUAL2(overlays[0].length, ed->document()->line(i).length(),"selection highlighting hasn't line length "+message); } }
void QSearchReplacePanelTest::incrementalsearch(){ QFETCH(QString, editorText); QFETCH(int, options); QFETCH(bool, cursor); QFETCH(int, sy); QFETCH(int, sx); QFETCH(QStringList, moves); QFETCH(int, scopey1); QFETCH(int, scopex1); QFETCH(int, scopey2); QFETCH(int, scopex2); for (int loop=0; loop<2; loop++) { panel->display(1,loop==1); ed->setText(editorText, false); if (scopey1!=-1) { widget->cbSelection->setChecked(true); ed->setCursor(ed->document()->cursor(scopey1,scopex1,scopey2,scopex2)); //test if the set search scope is correctly highlighted QCEMULTIEQUAL(getHighlightedSelection(ed), panel->getSearchScope(), ed->document()->cursor(scopey1,scopex1,scopey2,scopex2)); } if (!cursor && loop!=0){ //reset, so it won't continue previous search panel->setOptions((QDocumentSearch::Options)options, true, scopey1!=-1); ed->setCursorPosition(0,0); } panel->setOptions((QDocumentSearch::Options)options, cursor, scopey1!=-1); ed->setCursorPosition(sy,sx); int cx=-1; int cy=-1; foreach (const QString& s, moves){ QString search=s; QStringList sl = s.split("|"); QVERIFY(sl.count()==1||sl.count()==3||sl.count()==4); if (sl.count()>=3){ cy=sl[0].toInt(); cx=sl[1].toInt(); search=sl[2]; } QString res=search; if (sl.count()==4) res=sl[3]; //it doesn't react to setText if (search.isEmpty()) { widget->cFind->setEditText("a"); widget->cFind->lineEdit()->cursorForward(false); QTest::keyClick(widget->cFind->lineEdit(),Qt::Key_Backspace); } else { widget->cFind->setEditText(search.left(search.length()-1)); widget->cFind->lineEdit()->cursorForward(false,search.length()); QTest::keyClick(widget->cFind->lineEdit(),search[search.length()-1].toLatin1()); } QDocumentCursor c=ed->cursor().selectionStart(); QEQUAL2(c.lineNumber(), cy, search+" "+ed->cursor().selectedText()+" "+QString::number(loop)); QEQUAL2(c.columnNumber(), cx, search+" "+ed->cursor().selectedText()); QEQUAL2(ed->cursor().selectedText(), res, search+" "+ed->cursor().selectedText()); //searching shouldn't change highlighted selection QCEMULTIEQUAL(getHighlightedSelection(ed), panel->getSearchScope(), ed->document()->cursor(scopey1,scopex1,scopey2,scopex2)); } }