当我在Visual Studio 2015测试资源管理器中执行测试时,我得到unicode编码的结果
void TestProduct::test_case1()
{
QString string = "Кириллица";
QString result = "кириллица";
qDebug() << string;
qDebug() << result;
QCOMPARE(string, result);
}输出为
PASS : 'initTestCase()'
FAIL : 'test_case1()' Compared values are not the same
Actual ((string)): "\u041A\u0438\u0440\u0438\u043B\u043B\u0438\u0446\u0430"
Expected (result) : "\u043A\u0438\u0440\u0438\u043B\u043B\u0438\u0446\u0430"
QDEBUG : "Кириллица"
QDEBUG : "кириллица"
tst_testproduct.cpp(33)有没有办法像qDebug那样以更易读的格式获得实际值和期望值的输出?
发布于 2019-07-24 00:31:06
找到了解决方案。
一旦QT Testlib打算输出QString值,它就会在内部调用toPrettyUnicode。为了修复它,我重写了toString函数:
char *toString(const QString &str)
{
return qstrdup(str.toUtf8().constData());
}https://stackoverflow.com/questions/57164057
复制相似问题