void QDocumentCursorTest::constMethods(){ QFETCH(QString, cursor); QFETCH(bool, atStart); QFETCH(bool, atEnd); QFETCH(bool, atLineStart); QFETCH(bool, atLineEnd); QFETCH(int, position); QFETCH(int, anchorLineNumber); QFETCH(int, anchorColumnNumber); QFETCH(int, lineNumber); QFETCH(int, columnNumber); QFETCH(QString, selectionStart); QFETCH(QString, selectionEnd); QFETCH(bool, hasSelection); QFETCH(QString, selectedText); QFETCH(char, previousChar); QFETCH(char, nextChar); Q_UNUSED(position) QDocumentCursor c=str2cur(cursor); QVERIFY(c.isValid()); QVERIFY(!c.isNull()); QVERIFY(c==c); QVERIFY(!(c!=c)); QVERIFY(c<=c); QVERIFY(c>=c); QVERIFY(!(c<c)); QVERIFY(!(c>c)); QEQUAL(c.atStart(), atStart); QEQUAL(c.atEnd(), atEnd); QEQUAL(c.atLineStart(), atLineStart); QEQUAL(c.atLineEnd(), atLineEnd); //QEQUAL(c.position(), position); QEQUAL(c.anchorLineNumber(), anchorLineNumber); QEQUAL(c.anchorColumnNumber(), anchorColumnNumber); QEQUAL(c.lineNumber(), lineNumber); QEQUAL(c.columnNumber(), columnNumber); QVERIFY(c.line()==doc->line(lineNumber)); QVERIFY(c.anchorLine()==doc->line(anchorLineNumber)); if (selectionStart == "") QVERIFY(c.selectionStart().isNull()); else QSVERIFY2(c.selectionStart() == str2cur(selectionStart),QString("%1:%2").arg(c.selectionStart().lineNumber()).arg(c.selectionStart().columnNumber())); if (selectionEnd == "") QVERIFY(c.selectionEnd().isNull()); else QSVERIFY2(c.selectionEnd() == str2cur(selectionEnd),QString("%1:%2").arg(c.selectionEnd().lineNumber()).arg(c.selectionEnd().columnNumber())); QEQUAL(c.hasSelection(), hasSelection); QEQUAL(c.selectedText(), selectedText); QEQUAL(c.previousChar(), previousChar); QEQUAL(c.nextChar(), nextChar); }
//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); } }