2013-03-02 63 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?? 

有什麼想法?

回答