summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNikolai Kosjar <nikolai.kosjar@digia.com>2014-05-08 13:21:42 -0400
committerNikolai Kosjar <nikolai.kosjar@digia.com>2014-05-23 14:24:10 +0200
commitcadc4b42bacf959258f7d4b19e93d02c02b63449 (patch)
tree132d8a7cfc02177f89b341ec92a9c856f05afcc8 /src
parent41aa2cb3bdd247898b32941270838ec6348cd755 (diff)
downloadqt-creator-cadc4b42bacf959258f7d4b19e93d02c02b63449.tar.gz
Cpp{Tools,Editor}: Tests: Use QString instead of QByteArray
This is necessary in order to add tests with multi-byte UTF-8 code points. Otherwise the initial and target source code marker positions will be calculated on the QByteArray (test code) but used with a QString (editor document). Change-Id: I108961b13d32912a4d3193cf26eb59f65d296f57 Reviewed-by: Erik Verbruggen <erik.verbruggen@digia.com>
Diffstat (limited to 'src')
-rw-r--r--src/plugins/cppeditor/cppdoxygen_test.cpp3
-rw-r--r--src/plugins/cppeditor/cppeditortestcase.cpp2
-rw-r--r--src/plugins/cppeditor/cppquickfix_test.cpp23
-rw-r--r--src/plugins/cppeditor/cppquickfix_test.h2
-rw-r--r--src/plugins/cppeditor/followsymbol_switchmethoddecldef_test.cpp2
-rw-r--r--src/plugins/cpptools/cpptoolstestcase.cpp13
-rw-r--r--src/plugins/cpptools/cpptoolstestcase.h4
7 files changed, 25 insertions, 24 deletions
diff --git a/src/plugins/cppeditor/cppdoxygen_test.cpp b/src/plugins/cppeditor/cppdoxygen_test.cpp
index d4a2ab9a94..6ee593784a 100644
--- a/src/plugins/cppeditor/cppdoxygen_test.cpp
+++ b/src/plugins/cppeditor/cppdoxygen_test.cpp
@@ -99,8 +99,7 @@ public:
QCOMPARE(QLatin1String(result), QLatin1String(expected));
testDocument.m_editorWidget->undo();
- const QByteArray contentsAfterUndo
- = testDocument.m_editorWidget->document()->toPlainText().toUtf8();
+ const QString contentsAfterUndo = testDocument.m_editorWidget->document()->toPlainText();
QCOMPARE(contentsAfterUndo, testDocument.m_source);
}
};
diff --git a/src/plugins/cppeditor/cppeditortestcase.cpp b/src/plugins/cppeditor/cppeditortestcase.cpp
index ea24125488..0f7fa32807 100644
--- a/src/plugins/cppeditor/cppeditortestcase.cpp
+++ b/src/plugins/cppeditor/cppeditortestcase.cpp
@@ -43,7 +43,7 @@ namespace Tests {
TestDocument::TestDocument(const QByteArray &fileName, const QByteArray &source, char cursorMarker)
: CppTools::Tests::TestDocument(fileName, source, cursorMarker)
- , m_cursorPosition(source.indexOf(m_cursorMarker))
+ , m_cursorPosition(m_source.indexOf(QLatin1Char(m_cursorMarker)))
, m_editor(0)
, m_editorWidget(0)
{
diff --git a/src/plugins/cppeditor/cppquickfix_test.cpp b/src/plugins/cppeditor/cppquickfix_test.cpp
index 4733947174..ad250f9900 100644
--- a/src/plugins/cppeditor/cppquickfix_test.cpp
+++ b/src/plugins/cppeditor/cppquickfix_test.cpp
@@ -77,12 +77,13 @@ QuickFixTestDocument::QuickFixTestDocument(const QByteArray &fileName,
const QByteArray &source,
const QByteArray &expectedSource)
: TestDocument(fileName, source)
- , m_expectedSource(expectedSource)
+ , m_expectedSource(QString::fromUtf8(expectedSource))
{
if (m_cursorPosition > -1)
m_source.remove(m_cursorPosition, 1);
- const int cursorPositionInExpectedSource = m_expectedSource.indexOf(m_cursorMarker);
+ const int cursorPositionInExpectedSource
+ = m_expectedSource.indexOf(QLatin1Char(m_cursorMarker));
if (cursorPositionInExpectedSource > -1)
m_expectedSource.remove(cursorPositionInExpectedSource, 1);
}
@@ -96,15 +97,15 @@ QList<QuickFixTestDocument::Ptr> singleDocument(const QByteArray &original,
/// Leading whitespace is not removed, so we can check if the indetation ranges
/// have been set correctly by the quick-fix.
-static QByteArray &removeTrailingWhitespace(QByteArray &input)
+static QString &removeTrailingWhitespace(QString &input)
{
- QList<QByteArray> lines = input.split('\n');
+ const QStringList lines = input.split(QLatin1Char('\n'));
input.resize(0);
for (int i = 0, total = lines.size(); i < total; ++i) {
- QByteArray line = lines.at(i);
+ QString line = lines.at(i);
while (line.length() > 0) {
- char lastChar = line[line.length() - 1];
- if (lastChar == ' ' || lastChar == '\t')
+ QChar lastChar = line[line.length() - 1];
+ if (lastChar == QLatin1Char(' ') || lastChar == QLatin1Char('\t'))
line.chop(1);
else
break;
@@ -113,7 +114,7 @@ static QByteArray &removeTrailingWhitespace(QByteArray &input)
const bool isLastLine = i == lines.size() - 1;
if (!isLastLine)
- input.append('\n');
+ input.append(QLatin1Char('\n'));
}
return input;
}
@@ -197,14 +198,14 @@ QuickFixTestCase::QuickFixTestCase(const QList<QuickFixTestDocument::Ptr> &theTe
// Compare all files
foreach (const QuickFixTestDocument::Ptr testFile, m_testFiles) {
// Check
- QByteArray result = testFile->m_editorWidget->document()->toPlainText().toUtf8();
+ QString result = testFile->m_editorWidget->document()->toPlainText();
removeTrailingWhitespace(result);
- QCOMPARE(QLatin1String(result), QLatin1String(testFile->m_expectedSource));
+ QCOMPARE(result, testFile->m_expectedSource);
// Undo the change
for (int i = 0; i < 100; ++i)
testFile->m_editorWidget->undo();
- result = testFile->m_editorWidget->document()->toPlainText().toUtf8();
+ result = testFile->m_editorWidget->document()->toPlainText();
QCOMPARE(result, testFile->m_source);
}
}
diff --git a/src/plugins/cppeditor/cppquickfix_test.h b/src/plugins/cppeditor/cppquickfix_test.h
index 2046f7a483..615e814104 100644
--- a/src/plugins/cppeditor/cppquickfix_test.h
+++ b/src/plugins/cppeditor/cppquickfix_test.h
@@ -62,7 +62,7 @@ public:
const QByteArray &expectedSource);
public:
- QByteArray m_expectedSource;
+ QString m_expectedSource;
};
/**
diff --git a/src/plugins/cppeditor/followsymbol_switchmethoddecldef_test.cpp b/src/plugins/cppeditor/followsymbol_switchmethoddecldef_test.cpp
index 09af39efc9..78d51fa91b 100644
--- a/src/plugins/cppeditor/followsymbol_switchmethoddecldef_test.cpp
+++ b/src/plugins/cppeditor/followsymbol_switchmethoddecldef_test.cpp
@@ -175,7 +175,7 @@ class TestDocument : public CppEditor::Internal::Tests::TestDocument
public:
TestDocument(const QByteArray &source, const QByteArray &fileName)
: CppEditor::Internal::Tests::TestDocument(fileName, source)
- , m_targetCursorPosition(source.indexOf('$'))
+ , m_targetCursorPosition(m_source.indexOf(QLatin1Char('$')))
{
if (m_cursorPosition != -1 || m_targetCursorPosition != -1)
QVERIFY(m_cursorPosition != m_targetCursorPosition);
diff --git a/src/plugins/cpptools/cpptoolstestcase.cpp b/src/plugins/cpptools/cpptoolstestcase.cpp
index 12c0218270..05eb856821 100644
--- a/src/plugins/cpptools/cpptoolstestcase.cpp
+++ b/src/plugins/cpptools/cpptoolstestcase.cpp
@@ -61,20 +61,21 @@ namespace CppTools {
namespace Tests {
TestDocument::TestDocument(const QByteArray &fileName, const QByteArray &source, char cursorMarker)
- : m_fileName(fileName), m_source(source), m_cursorMarker(cursorMarker)
+ : m_fileName(QString::fromUtf8(fileName))
+ , m_source(QString::fromUtf8(source))
+ , m_cursorMarker(cursorMarker)
{}
QString TestDocument::filePath() const
{
- const QString fileNameAsString = QString::fromUtf8(m_fileName);
- if (!QFileInfo(fileNameAsString).isAbsolute())
- return QDir::tempPath() + QLatin1Char('/') + fileNameAsString;
- return fileNameAsString;
+ if (!QFileInfo(m_fileName).isAbsolute())
+ return QDir::tempPath() + QLatin1Char('/') + m_fileName;
+ return m_fileName;
}
bool TestDocument::writeToDisk() const
{
- return TestCase::writeFile(filePath(), m_source);
+ return TestCase::writeFile(filePath(), m_source.toUtf8());
}
TestCase::TestCase(bool runGarbageCollector)
diff --git a/src/plugins/cpptools/cpptoolstestcase.h b/src/plugins/cpptools/cpptoolstestcase.h
index a3c2529568..1871c96e68 100644
--- a/src/plugins/cpptools/cpptoolstestcase.h
+++ b/src/plugins/cpptools/cpptoolstestcase.h
@@ -56,8 +56,8 @@ public:
bool writeToDisk() const;
public:
- QByteArray m_fileName;
- QByteArray m_source;
+ QString m_fileName;
+ QString m_source;
char m_cursorMarker;
};