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>
This commit is contained in:
Nikolai Kosjar
2014-05-08 13:21:42 -04:00
parent 41aa2cb3bd
commit cadc4b42ba
7 changed files with 25 additions and 24 deletions

View File

@@ -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)

View File

@@ -56,8 +56,8 @@ public:
bool writeToDisk() const;
public:
QByteArray m_fileName;
QByteArray m_source;
QString m_fileName;
QString m_source;
char m_cursorMarker;
};