繁体   English   中英

如何更改QtTest输出的编码?

[英]How to change encoding of the QtTest output?

当我在Visual Studio 2015 Test Explorer下执行测试时,我得到了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一样以更易读的格式获取实际值和期望值的输出?

找到了解决方案。

一旦打算输出QString值,QT Testlib就在内部调用toPrettyUnicode 为了解决这个问题,我重写了toString函数:

char *toString(const QString &str)
{
    return qstrdup(str.toUtf8().constData());
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM