include overall state in exit code
This commit is contained in:
@@ -22,6 +22,29 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
static bool error = false;
|
||||
|
||||
void verify(bool expectFailMatch, string type, string input,
|
||||
bool match, string expectStr, string gotStr)
|
||||
{
|
||||
match = match && expectStr == gotStr;
|
||||
if (expectFailMatch) {
|
||||
if (match) {
|
||||
cout << " failed " << type << " match >" << input
|
||||
<< "< error: unexpectedly succeeded" << endl;
|
||||
error = true;
|
||||
} else {
|
||||
cout << " failed " << type << " match >" << input << "< OK" << endl;
|
||||
}
|
||||
} else if (match) {
|
||||
cout << " " << type << " match >" << input << "< OK" << endl;
|
||||
} else {
|
||||
cout << " " << type << " match >" << input << "< error: got >"
|
||||
<< gotStr << "<, expected >" << expectStr << "<" << endl;
|
||||
error = true;
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
SymbolString sstr(true);
|
||||
@@ -38,51 +61,36 @@ int main(int argc, char** argv)
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
string gotStr, expectStr;
|
||||
result_t result = sstr.parseHex("10feb5050427a915aa", false);
|
||||
if (result != RESULT_OK)
|
||||
if (result != RESULT_OK) {
|
||||
cout << "parse escaped error: " << getResultCode(result) << endl;
|
||||
error = true;
|
||||
} else {
|
||||
gotStr = sstr.getDataStr(false, false), expectStr = "10feb5050427a90015a90177";
|
||||
verify(false, "parse escaped", "10feb5050427a915aa", true, expectStr, gotStr);
|
||||
unsigned char gotCrc = sstr.getCRC(), expectCrc = 0x77;
|
||||
ostringstream ostr;
|
||||
ostr << nouppercase << setw(2) << hex << setfill('0') << static_cast<unsigned>(expectCrc);
|
||||
expectStr = ostr.str();
|
||||
ostr.str("");
|
||||
ostr << nouppercase << setw(2) << hex << setfill('0') << static_cast<unsigned>(gotCrc);
|
||||
gotStr = ostr.str();
|
||||
verify(false, "CRC", "10feb5050427a915aa", gotCrc==expectCrc, expectStr, gotStr);
|
||||
|
||||
string gotStr = sstr.getDataStr(false, false), expectStr = "10feb5050427a90015a90177";
|
||||
|
||||
if (strcasecmp(gotStr.c_str(), expectStr.c_str()) == 0)
|
||||
cout << "parse escaped OK" << endl;
|
||||
else
|
||||
cout << "parse escaped error: got " << gotStr << ", expected "
|
||||
<< expectStr << endl;
|
||||
|
||||
unsigned char gotCrc = sstr.getCRC(), expectCrc = 0x77;
|
||||
|
||||
if (gotCrc == expectCrc)
|
||||
cout << "CRC OK" << endl;
|
||||
else
|
||||
cout << "CRC error: got 0x" << nouppercase << setw(2)
|
||||
<< hex << setfill('0')
|
||||
<< static_cast<unsigned>(gotCrc) << ", expected 0x"
|
||||
<< nouppercase << setw(2) << hex
|
||||
<< setfill('0') << static_cast<unsigned>(expectCrc)
|
||||
<< endl;
|
||||
|
||||
gotStr = sstr.getDataStr(true, false), expectStr = "10feb5050427a915aa77";
|
||||
|
||||
if (strcasecmp(gotStr.c_str(), expectStr.c_str()) == 0)
|
||||
cout << "unescape OK" << endl;
|
||||
else
|
||||
cout << "unescape error: got " << gotStr << ", expected "
|
||||
<< expectStr << endl;
|
||||
gotStr = sstr.getDataStr(true, false), expectStr = "10feb5050427a915aa77";
|
||||
verify(false, "unescape", "10feb5050427a915aa", true, expectStr, gotStr);
|
||||
}
|
||||
|
||||
sstr = SymbolString(false);
|
||||
result = sstr.parseHex("10feb5050427a90015a90177", true);
|
||||
if (result != RESULT_OK)
|
||||
if (result != RESULT_OK) {
|
||||
cout << "parse unescaped error: " << getResultCode(result) << endl;
|
||||
error = true;
|
||||
} else {
|
||||
gotStr = sstr.getDataStr(true, false), expectStr = "10feb5050427a915aa77";
|
||||
verify(false, "parse unescaped", "10feb5050427a90015a90177", true, expectStr, gotStr);
|
||||
}
|
||||
|
||||
gotStr = sstr.getDataStr(true, false);
|
||||
|
||||
if (strcasecmp(gotStr.c_str(), expectStr.c_str()) == 0)
|
||||
cout << "parse unescaped OK" << endl;
|
||||
else
|
||||
cout << "parse unescaped error: got " << gotStr << ", expected "
|
||||
<< expectStr << endl;
|
||||
|
||||
return 0;
|
||||
|
||||
return error ? 1 : 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user