added check for decode via loaded MessageMap
This commit is contained in:
@@ -47,11 +47,13 @@ int main()
|
|||||||
// field= name;[pos];type[;[divisor|values][;[unit][;[comment]]]]
|
// field= name;[pos];type[;[divisor|values][;[unit][;[comment]]]]
|
||||||
string checks[][5] = {
|
string checks[][5] = {
|
||||||
// "message", "flags"
|
// "message", "flags"
|
||||||
{"c;;first;;;fe;0700;;x;;bda", "26.10.2014", "fffe0700042610061451", "00", "p"},
|
{"u;;first;;;fe;0700;;x;;bda", "26.10.2014", "fffe0700042610061451", "00", "p"},
|
||||||
{"w;;first;;;15;b509;0400;date;;bda", "26.10.2014", "ff15b5090604002610061445", "00", "m"},
|
{"w;;first;;;15;b509;0400;date;;bda", "26.10.2014", "ff15b5090604002610061445", "00", "m"},
|
||||||
{"r;ehp;time;;;08;b509;0d2800;;;time", "15:00:17", "ff08b509030d2800ea", "0311000f00", "m"},
|
{"r;ehp;time;;;08;b509;0d2800;;;time", "15:00:17", "ff08b509030d2800ea", "0311000f00", "m"},
|
||||||
{"r;ehp;date;;;08;b509;0d2900;;;hda:3", "23.11.2014", "ff08b509030d290071", "03170b0e5a", "m"},
|
{"r;ehp;date;;;08;b509;0d2900;;;hda:3", "23.11.2014", "ff08b509030d290071", "03170b0e5a", "m"},
|
||||||
{"c;ehp;ActualEnvironmentPower;Energiebezug;;08;B509;29BA00;;s;IGN:2;;;;;s;power", "8", "1008b5090329ba00", "03ba0008", "p"},
|
{"u;ehp;ActualEnvironmentPower;Energiebezug;;08;B509;29BA00;;s;IGN:2;;;;;s;power", "8", "1008b5090329ba00", "03ba0008", "pm"},
|
||||||
|
{"","55.50;ok","1025b50903290000","050000780300",""},
|
||||||
|
|
||||||
};
|
};
|
||||||
DataFieldTemplates* templates = new DataFieldTemplates();
|
DataFieldTemplates* templates = new DataFieldTemplates();
|
||||||
result_t result = templates->readFromFile("_types.csv");
|
result_t result = templates->readFromFile("_types.csv");
|
||||||
@@ -90,69 +92,90 @@ int main()
|
|||||||
delete deleteMessage;
|
delete deleteMessage;
|
||||||
deleteMessage = NULL;
|
deleteMessage = NULL;
|
||||||
}
|
}
|
||||||
vector<string>::iterator it = entries.begin();
|
if (entries.size() == 0) {
|
||||||
result_t result = Message::create(it, entries.end(), NULL, templates, deleteMessage);
|
message = messages->find(mstr);
|
||||||
|
if (message == NULL) {
|
||||||
if (failedCreate == true) {
|
cout << " find error: NULL" << endl;
|
||||||
if (result == RESULT_OK)
|
continue;
|
||||||
cout << "\"" << check[0] << "\": failed create error: unexpectedly succeeded" << endl;
|
}
|
||||||
else
|
cout << " find OK" << endl;
|
||||||
cout << "\"" << check[0] << "\": failed create OK" << endl;
|
} else {
|
||||||
continue;
|
vector<string>::iterator it = entries.begin();
|
||||||
}
|
result = Message::create(it, entries.end(), NULL, templates, deleteMessage);
|
||||||
if (result != RESULT_OK) {
|
if (failedCreate == true) {
|
||||||
cout << "\"" << check[0] << "\": create error: "
|
if (result == RESULT_OK)
|
||||||
<< getResultCode(result) << endl;
|
cout << "\"" << check[0] << "\": failed create error: unexpectedly succeeded" << endl;
|
||||||
printErrorPos(entries.begin(), entries.end(), it);
|
else
|
||||||
continue;
|
cout << "\"" << check[0] << "\": failed create OK" << endl;
|
||||||
}
|
continue;
|
||||||
if (deleteMessage == NULL) {
|
}
|
||||||
cout << "\"" << check[0] << "\": create error: NULL" << endl;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (it != entries.end()) {
|
|
||||||
cout << "\"" << check[0] << "\": create error: trailing input" << endl;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
cout << "\"" << check[0] << "\": create OK" << endl;
|
|
||||||
|
|
||||||
if (dontMap == false) {
|
|
||||||
result = messages->add(deleteMessage);
|
|
||||||
if (result != RESULT_OK) {
|
if (result != RESULT_OK) {
|
||||||
cout << "\"" << check[0] << "\": add error: "
|
cout << "\"" << check[0] << "\": create error: "
|
||||||
|
<< getResultCode(result) << endl;
|
||||||
|
printErrorPos(entries.begin(), entries.end(), it);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (deleteMessage == NULL) {
|
||||||
|
cout << "\"" << check[0] << "\": create error: NULL" << endl;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (it != entries.end()) {
|
||||||
|
cout << "\"" << check[0] << "\": create error: trailing input" << endl;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
cout << "\"" << check[0] << "\": create OK" << endl;
|
||||||
|
if (dontMap == false) {
|
||||||
|
result_t result = messages->add(deleteMessage);
|
||||||
|
if (result != RESULT_OK) {
|
||||||
|
cout << "\"" << check[0] << "\": add error: "
|
||||||
|
<< getResultCode(result) << endl;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
cout << " map OK" << endl;
|
||||||
|
message = deleteMessage;
|
||||||
|
deleteMessage = NULL;
|
||||||
|
if (messages->find(mstr) == message)
|
||||||
|
cout << " find OK" << endl;
|
||||||
|
else
|
||||||
|
cout << " find error: NULL" << endl;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
message = deleteMessage;
|
||||||
|
}
|
||||||
|
istringstream input(inputStr);
|
||||||
|
SymbolString writeMstr = SymbolString();
|
||||||
|
if (message->isPassive() == true) {
|
||||||
|
ostringstream output;
|
||||||
|
result = message->decode(mstr, sstr, output);
|
||||||
|
if (result != RESULT_OK) {
|
||||||
|
cout << " \"" << inputStr << "\": decode error: "
|
||||||
<< getResultCode(result) << endl;
|
<< getResultCode(result) << endl;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
cout << " map OK" << endl;
|
cout << " \"" << inputStr << "\": decode OK" << endl;
|
||||||
message = deleteMessage;
|
|
||||||
deleteMessage = NULL;
|
|
||||||
if (messages->find(mstr) == message)
|
|
||||||
cout << " find OK" << endl;
|
|
||||||
else
|
|
||||||
cout << " find error: NULL" << endl;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
message = deleteMessage;
|
|
||||||
istringstream input(inputStr);
|
|
||||||
SymbolString writeMstr = SymbolString();
|
|
||||||
result = message->prepare(0xff, writeMstr, input);
|
|
||||||
if (failedPrepare == true) {
|
|
||||||
if (result == RESULT_OK)
|
|
||||||
cout << " \"" << inputStr << "\": failed prepare error: unexpectedly succeeded" << endl;
|
|
||||||
else
|
|
||||||
cout << " \"" << inputStr << "\": failed prepare OK" << endl;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (result != RESULT_OK) {
|
bool match = inputStr == output.str();
|
||||||
cout << " \"" << inputStr << "\": prepare error: "
|
verify(false, "decode", check[2] + "/" + check[3], match, inputStr, output.str());
|
||||||
<< getResultCode(result) << endl;
|
} else {
|
||||||
continue;
|
result = message->prepareMaster(0xff, writeMstr, input);
|
||||||
}
|
if (failedPrepare == true) {
|
||||||
cout << " \"" << inputStr << "\": prepare OK" << endl;
|
if (result == RESULT_OK)
|
||||||
|
cout << " \"" << inputStr << "\": failed prepare error: unexpectedly succeeded" << endl;
|
||||||
|
else
|
||||||
|
cout << " \"" << inputStr << "\": failed prepare OK" << endl;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
bool match = writeMstr==mstr;
|
if (result != RESULT_OK) {
|
||||||
verify(failedPrepareMatch, "prepare", inputStr, match, mstr.getDataStr(), writeMstr.getDataStr());
|
cout << " \"" << inputStr << "\": prepare error: "
|
||||||
|
<< getResultCode(result) << endl;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
cout << " \"" << inputStr << "\": prepare OK" << endl;
|
||||||
|
|
||||||
|
bool match = writeMstr==mstr;
|
||||||
|
verify(failedPrepareMatch, "prepare", inputStr, match, mstr.getDataStr(), writeMstr.getDataStr());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (deleteMessage != NULL) {
|
if (deleteMessage != NULL) {
|
||||||
|
|||||||
Reference in New Issue
Block a user