2013-03-02 64 views
0

我有一些简单的代码可以反转QString。QTestLib结果与程序输出不同

const QString reverse_qstring(const QString& str_in) 
{ 
    QString out; 
    Q_FOREACH(const QChar c, str_in) { 
     out.push_front(c); 
    } 
    return out; 
} 

当我从非ASCII字符的命令行中输入文本,事情会如预期:

"¿como estás?" : "?sátse omoc¿" 

然而,当我提出以下的单元测试(使用QTestLib):

QCOMPARE(reverse_qstring(QString("¿como estás?")), QString("?sátse omoc¿")); 

我得到:

FAIL! : program::test_qstring() Compared values are not the same 
    Actual (reverse_qstring(QString("??como est??s?"))): ?s??tse omoc?? 
    Expected (QString("?s??tse omoc??")): ?s??tse omoc?? 

有什么想法?

回答