completed implementation of QrCode::toString

This commit is contained in:
favoritas37 2017-08-23 01:07:23 +03:00
parent 3c18b88aed
commit fe43ed8788
4 changed files with 36 additions and 23 deletions

View File

@ -61,10 +61,11 @@ public:
bool operator==(const Mode& other); bool operator==(const Mode& other);
bool operator!=(const Mode& other); bool operator!=(const Mode& other);
std::string getName() const { return name_; } std::string getName() const {
if(name_ == "")
std::string toString() const { return "null";
return getName(); else
return name_;
} }
}; };
} }

View File

@ -45,22 +45,36 @@ const std::string QRCode::toString()
{ {
std::stringstream result; std::stringstream result;
result << "<<"; result << "<<";
// result << "\n mode: {unimpl}";
// result << mode_; result << "\n mode: ";
result << "\n ecLevel: {unimpl}"; result << mode_.getName();
//result << ecLevel_;
result << "\n version: {unimpl}"; result << "\n ecLevel: ";
//result << version_; if(!ecLevel_ptr_.empty())
result << ecLevel_ptr_->name();
else
result << "null";
result << "\n version: ";
if(!version_ptr_.empty())
{
std::string version_str;
std::ostringstream convert;
convert << version_ptr_->getVersionNumber();
version_str = convert.str();
result << version_str;
}
else
result << "null";
result << "\n maskPattern: "; result << "\n maskPattern: ";
result << maskPattern_; result << maskPattern_;
// if (matrix_ == null) {
// result.append("\n matrix: null\n");
// } else {
if (matrix_ptr_) if (matrix_ptr_)
result << "\n matrix:\n" << matrix_ptr_->toString(); result << "\n matrix:\n" << matrix_ptr_->toString();
else else
result << "\n matrix: null\n"; result << "\n matrix: null\n";
// }
result << "\n>>"; result << "\n>>";
return result.str(); return result.str();
} }

View File

@ -50,7 +50,7 @@ private:
} }
static QString itemToString(qrcode::Mode& item) { static QString itemToString(qrcode::Mode& item) {
return QString::fromStdString(item.toString()); return QString::fromStdString(item.getName());
} }
protected: protected:

View File

@ -50,9 +50,9 @@ void QRCodeTests::testToString1() {
QRCode qrCode; QRCode qrCode;
std::string expected = std::string expected =
"<<\n" "<<\n"
// " mode: null\n" " mode: null\n"
" ecLevel: {unimpl}\n" " ecLevel: null\n"
" version: {unimpl}\n" " version: null\n"
" maskPattern: -1\n" " maskPattern: -1\n"
" matrix: null\n" " matrix: null\n"
"\n>>"; "\n>>";
@ -74,11 +74,9 @@ void QRCodeTests::testToString2()
} }
qrCode.setMatrix(matrix); qrCode.setMatrix(matrix);
std::string expected = "<<\n" std::string expected = "<<\n"
//" mode: BYTE\n" " mode: BYTE\n"
//" ecLevel: H\n" " ecLevel: H\n"
" ecLevel: {unimpl}\n" " version: 1\n"
//" version: 1\n"
" version: {unimpl}\n"
" maskPattern: 3\n" " maskPattern: 3\n"
" matrix:\n" " matrix:\n"
" 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0\n" " 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0\n"