From 20884ce2690b9786674c87d293e47d11cdb08fe1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCri=20Valdmann?= Date: Wed, 22 Aug 2018 15:03:05 +0200 Subject: Add more error output to qwebengine_convert_dict Task-number: QTBUG-70034 Change-Id: Ia1c18845f480225e3f50cf7199cdf85a3fb4f158 Reviewed-by: Kai Koehne --- src/tools/qwebengine_convert_dict/main.cpp | 40 +++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/tools/qwebengine_convert_dict/main.cpp b/src/tools/qwebengine_convert_dict/main.cpp index 3a1a1ff64..2a82e5945 100644 --- a/src/tools/qwebengine_convert_dict/main.cpp +++ b/src/tools/qwebengine_convert_dict/main.cpp @@ -17,6 +17,7 @@ ******************************************************************************/ #include +#include #include #include #include @@ -61,6 +62,20 @@ inline QString toQt(const std::string &string) return QString::fromStdString(string); } +template +QTextStream &operator<<(QTextStream &out, base::span span) +{ + out << '['; + QString prefix; + for (const auto &element : span) { + out << prefix; + out << element; + prefix = QStringLiteral(","); + } + out << ']'; + return out; +} + // Compares the given word list with the serialized trie to make sure they // are the same. inline bool VerifyWords(const convert_dict::DicReader::WordList& org_words, @@ -86,22 +101,23 @@ inline bool VerifyWords(const convert_dict::DicReader::WordList& org_words, } if (org_words[i].first != buf) { - out << "Word doesn't match, word #" << buf << endl; + out << "Word does not match!\n" + << " Index: " << i << "\n" + << " Expected: " << QString::fromStdString(org_words[i].first) << "\n" + << " Actual: " << QString::fromUtf8(buf) << endl; return false; } - if (affix_matches != static_cast(org_words[i].second.size())) { - out << "Different number of affix indices, word #" << buf << endl; - return false; - } + base::span expectedAffixes(org_words[i].second); + base::span actualAffixes(affix_ids, affix_matches); - // Check the individual affix indices. - for (size_t affix_index = 0; affix_index < org_words[i].second.size(); - affix_index++) { - if (affix_ids[affix_index] != org_words[i].second[affix_index]) { - out << "Index doesn't match, word #" << buf << endl; - return false; - } + if (expectedAffixes != actualAffixes) { + out << "Affixes do not match!\n" + << " Index: " << i << "\n" + << " Word: " << QString::fromUtf8(buf) << "\n" + << " Expected: " << expectedAffixes << "\n" + << " Actual: " << actualAffixes << endl; + return false; } } -- cgit v1.2.3