File: qdocumentline_t.cpp

package info (click to toggle)
texstudio 2.11.2%2Bdebian-1
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 41,292 kB
  • ctags: 12,405
  • sloc: cpp: 93,072; xml: 10,217; ansic: 4,153; sh: 145; makefile: 56
file content (127 lines) | stat: -rw-r--r-- 4,435 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#ifndef QT_NO_DEBUG
#include "qdocumentline_t.h"

//Actually this is a qdocumentlinehandle test, but they are almost the same

//----
//force full access to qdocument things
#define private public
#include "qdocument_p.h"
#include "qdocumentline_p.h"
#undef private
//----

#include "qeditor.h"
#include "qdocumentline.h"
#include "qdocumentline_p.h"
#include "testutil.h"
#include "smallUsefulFunctions.h"
#include <QtTest/QtTest>
Q_DECLARE_METATYPE(QList<int>);

QDocumentLineTest::QDocumentLineTest()
{
	doc=new QDocument(this);

}
QDocumentLineTest::~QDocumentLineTest(){
}

void QDocumentLineTest::initTestCase(){
	savedFixedPitch = QDocumentPrivate::m_fixedPitch;
	savedSpaceWidth = QDocumentPrivate::m_spaceWidth;
	savedLeftMargin = QDocumentPrivate::m_leftMargin;

	savedWorkAroundFPM = doc->hasWorkAround(QDocument::DisableFixedPitchMode);
	savedWorkAroundFSCD = doc->hasWorkAround(QDocument::ForceSingleCharacterDrawing);
	savedWorkAroundFQTL = doc->hasWorkAround(QDocument::ForceQTextLayout);
	
	doc->impl()->setHardLineWrap(false);
	doc->setWorkAround(QDocument::DisableFixedPitchMode, false);
	doc->setWorkAround(QDocument::ForceSingleCharacterDrawing, false);
	doc->setWorkAround(QDocument::ForceQTextLayout, false);
	QDocumentPrivate::m_fixedPitch = true;
	QDocumentPrivate::m_leftMargin = 0;
	QDocumentPrivate::m_spaceWidth = 5;
}

void QDocumentLineTest::cleanupTestCase(){
	QDocumentPrivate::m_fixedPitch = savedFixedPitch;
	QDocumentPrivate::m_spaceWidth = savedSpaceWidth;
	QDocumentPrivate::m_leftMargin = savedLeftMargin;
	doc->setWorkAround(QDocument::DisableFixedPitchMode, savedWorkAroundFPM);
	doc->setWorkAround(QDocument::ForceSingleCharacterDrawing, savedWorkAroundFSCD);
	doc->setWorkAround(QDocument::ForceQTextLayout, savedWorkAroundFQTL);
}

typedef QPair<int, int> IntPair;

void QDocumentLineTest::updateWrap_data(){
	QTest::addColumn<QString>("line");
	QTest::addColumn<int>("width");

	//every letter = 5px

	QTest::newRow("no wrap") << "abc" << 20;
	QTest::newRow("no wrap - exact hit") << "abcd" << 20;
	QTest::newRow("one pixel off") << "abc|d" << 19;
	QTest::newRow("3 lines force-break") << "abcd|efgh|ijkl" << 20;
	QTest::newRow("3 lines force-break - 2px waste") << "abcd|efgh|ijkl" << 22;
	QTest::newRow("3 lines force-break - 3px waste") << "abcd|efgh|ijkl" << 23;
	QTest::newRow("4 lines force-break - 2px off") << "abc|def|ghi|jkl" << 18;
	QTest::newRow("word break") << "ab |cde" << 20;
	QTest::newRow("word break - 2 spaces") << "ab  |cde" << 20;//??
	QTest::newRow("word break - 3 spaces nowhere to go") << "ab  | cde" << 20;
	QTest::newRow("word break - 4 spaces nowhere to go") << "ab  |  cd" << 20;
	QTest::newRow("word break - 4 spaces nowhere to go") << "ab  |  |cde" << 20;
	QTest::newRow("word break - space bug") << "a |a  x" << 20;
	QTest::newRow("space break") << "x   |    |    |   " << 20;
	QTest::newRow("space break - 1px off") << "x  |   |   |   " << 19;
	QTest::newRow("indentation break 1") << " abc|def|ghi" << 20;
	QTest::newRow("indentation break 2") << "  ab|cd|ef" << 20;
	QTest::newRow("indentation break 2 - word") << "  ax |bcd" << 30;
	QTest::newRow("indentation breaking") << "    |    |    |   " << 20;
	QTest::newRow("indentation breaking cat") << "    |    |    |   |miau" << 20;
	QTest::newRow("indentation breaking cat in 3d") << "    |    |    |   |miau|xyz" << 20;
}

void QDocumentLineTest::updateWrap(){
	QFETCH(QString, line);
	QFETCH(int, width);

	QString temp=line; temp.replace("|","");
	doc->setText(temp+"\n\n\n",false);
	doc->setWidthConstraint(width);

	QString fExp, fGot;
	QList<int> frontiers;
	for (int i=0;i<line.size();i++)
		if (line.at(i)=='|')
			frontiers << (i - frontiers.size());
	foreach(const int p, frontiers) fExp += QString("<%1:%2>").arg(p).arg(p*5);
	foreach(const IntPair& p, doc->line(0).handle()->m_frontiers) fGot += QString("<%1:%2>").arg(p.first).arg(p.second);
		
	QEQUAL(fGot, fExp);

	
	//-------test hard line wrap----
	QList<QDocumentLineHandle*> handles;
	for (int i=0;i<doc->lines();i++)
		handles << doc->line(i).handle();
	doc->applyHardLineWrap(handles);
	
	QStringList hlw = line.split('|');
	QString indent; 
	for (int i=0;i<hlw.first().length();i++) 
		if (hlw.first()[i].isSpace()) indent += hlw.first()[i];
		else break;
	if (indent == hlw.first()) indent = "";
	for (int i=1;i<hlw.size();i++)
		hlw[i] = indent + hlw[i];
	hlw << "" << "" << "";
	
	QEQUAL(doc->text(), hlw.join("\n"));
	
}

#endif