reworked filereader

This commit is contained in:
john30
2017-03-19 21:18:38 +01:00
parent 380ba2d19d
commit f26dbe7b4f
11 changed files with 971 additions and 640 deletions
+85 -49
View File
@@ -23,6 +23,8 @@
#include "lib/ebus/data.h"
using namespace ebusd;
using std::cout;
using std::endl;
static bool error = false;
@@ -31,25 +33,66 @@ void verify(bool expectFailMatch, string type, string input,
match = match && expectStr == gotStr;
if (expectFailMatch) {
if (match) {
error = true;
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 {
error = true;
cout << " " << type << " match >" << input << "< error: got >"
<< gotStr << "<, expected >" << expectStr << "<" << endl;
error = true;
}
}
class TestReader : public MappedFileReader {
public:
TestReader(DataFieldTemplates* templates, bool isSet, bool isMasterDest)
: MappedFileReader::MappedFileReader(true), m_templates(templates), m_isSet(isSet), m_isMasterDest(isMasterDest),
m_fields(NULL) {}
result_t getFieldMap(vector<string>& row, string& errorDescription) override {
if (row.empty()) {
row.push_back("*name");
row.push_back("part");
row.push_back("type");
row.push_back("divisor/values");
row.push_back("unit");
row.push_back("comment");
return RESULT_OK;
}
if (row[0][0] != '*') {
return RESULT_ERR_INVALID_ARG;
}
return RESULT_OK; // leave it to DataField::create
}
result_t addFromFile(map<string, string>& row, vector< map<string, string> >& subRows,
string& errorDescription, const string filename, unsigned int lineNo) override {
if (!row.empty() || subRows.empty()) {
cout << "read line " << static_cast<unsigned>(lineNo) << ": read error: got "
<< static_cast<unsigned>(row.size()) << "/0 main, " << static_cast<unsigned>(subRows.size())
<< "/>=3 sub" << endl;
return RESULT_ERR_EOF;
}
cout << "read line " << static_cast<unsigned>(lineNo) << ": read OK" << endl;
return DataField::create(subRows, errorDescription, m_templates, m_fields, m_isSet, false, m_isMasterDest);
}
private:
DataFieldTemplates* m_templates;
const bool m_isSet;
const bool m_isMasterDest;
public:
DataField* m_fields;
};
int main() {
// entry: definition, decoded value, master data, slave data, flags
// definition: name,part,type[:len][,[divisor|values][,[unit][,[comment]]]]
unsigned int baseLine = __LINE__+1;
string checks[][5] = {
// entry: definition, decoded value, master data, slave data, flags
// definition: name,part,type[:len][,[divisor|values][,[unit][,[comment]]]]
{"x,,ign:10", "", "10fe07000a00000000000000000000", "00", ""},
{"x,,ign:*", "", "10fe07000a00000000000000000000", "00", "W"},
{"x,,ign,2", "", "", "", "c"},
@@ -59,8 +102,7 @@ int main() {
{"x,,str:10", " ", "10fe07000a20202020202020202020", "00", ""},
{"x,,str:10", "", "10fe07000a20202020202020202020", "00", "R"},
{"x,,str:11", "", "10fe07000a20202020202020202020", "00", "rW"},
{"x,,str:24", "abcdefghijklmnopqrstuvwx", "10fe0700186162636465666768696a6b6c6d6e6f707172737475767778",
"00", ""},
{"x,,str:24", "abcdefghijklmnopqrstuvwx", "10fe0700186162636465666768696a6b6c6d6e6f707172737475767778", "00", ""},
{"x,,str:*", "abcde", "10fe0700056162636465", "00", ""},
{"x,,str,2", "", "", "", "c"},
{"x,,str:10,=dummy", "", "10fe07000a48616c6c6f2044752120", "00", "W"},
@@ -74,8 +116,7 @@ int main() {
{"x,,nts:10", "", "10fe07000a00000000000000000000", "00", ""},
{"x,,nts:10", "abc", "10fe07000a6162630065666768696a", "00", "W"},
{"x,,nts:11", "", "10fe07000a20202020202020202020", "00", "rW"},
{"x,,nts:24", "abcdefghijklmnopqrstuvwx", "10fe0700186162636465666768696a6b6c6d6e6f707172737475767778",
"00", ""},
{"x,,nts:24", "abcdefghijklmnopqrstuvwx", "10fe0700186162636465666768696a6b6c6d6e6f707172737475767778", "00", ""},
{"x,,nts:*", "abcde", "10fe0700056162636465", "00", "W"},
{"x,,nts:*", "abcde", "10fe070006616263646500", "00", ""},
{"x,,nts,2", "", "", "", "c"},
@@ -396,8 +437,7 @@ int main() {
{"x,,ulg", "-", "10feffff04ffffffff", "00", ""},
{"x,,ulg,10", "3.8", "10feffff0426000000", "00", ""},
{"x,,ulg,-10", "380", "10feffff0426000000", "00", ""},
{"x,,ulg,0x0FF0F00F = VRT 350 ;0x33CCCC33=VRT 360;0x3CC3C33C=SD 17;0x66999966=SD 37;0x69969669=VRT 360+",
"VRT 350", "10feffff040FF0F00F", "00", ""},
{"x,,ulg,0x0FF0F00F = VRT 350 ;0x33CCCC33=VRT 360;0x3CC3C33C=SD 17;0x66999966=SD 37;0x69969669=VRT 360+", "VRT 350", "10feffff040FF0F00F", "00", ""},
{"x,,ulg,0x=test", "", "10feffff040FF0F00F", "00", "c"},
{"x,,ulr", "38", "10feffff0400000026", "00", ""},
{"x,,ulr", "0", "10feffff0400000000", "00", ""},
@@ -433,19 +473,12 @@ int main() {
{"x,,bi3:2,0=off;1=on,ja/nein,Wahrheitswert", "x=on ja/nein [Wahrheitswert]", "10feffff0108", "00", "vvv"},
{"x,,bi3:2,0=off;1=on,ja/nein,Wahrheitswert", "x=1 ja/nein [Wahrheitswert]", "10feffff0108", "00", "vvvn"},
{"x,,bi3:2,0=off;1=on,ja/nein,Wahrheitswert", "\n \"x\": {\"value\": \"on\"}", "10feffff0108", "00", "vj"},
{",,bi3:2,0=off;1=on,ja/nein,Wahrheitswert", "\n \"0\": {\"name\": \"\", \"value\": \"on\"}", "10feffff0108",
"00", "vj"},
{",,bi3:2,0=off;1=on,ja/nein,Wahrheitswert", "\n \"0\": {\"name\": \"\", \"value\": \"on\"}", "10feffff0108",
"00", "j"},
{"x,,bi3:2,0=off;1=on,ja/nein,Wahrheitswert",
"\n \"x\": {\"value\": \"on\", \"unit\": \"ja/nein\", \"comment\": \"Wahrheitswert\"}", "10feffff0108",
"00", "vvvj"},
{",,bi3:2,0=off;1=on,ja/nein,Wahrheitswert", "\n \"0\": {\"name\": \"\", \"value\": \"on\"}", "10feffff0108", "00", "vj"},
{",,bi3:2,0=off;1=on,ja/nein,Wahrheitswert", "\n \"0\": {\"name\": \"\", \"value\": \"on\"}", "10feffff0108", "00", "j"},
{"x,,bi3:2,0=off;1=on,ja/nein,Wahrheitswert", "\n \"x\": {\"value\": \"on\", \"unit\": \"ja/nein\", \"comment\": \"Wahrheitswert\"}", "10feffff0108", "00", "vvvj"},
{"x,,bi3:2,0=off;1=on,ja/nein,Wahrheitswert", "\n \"x\": {\"value\": 1}", "10feffff0108", "00", "vnj"},
{"x,,bi3:2,0=off;1=on,ja/nein,Wahrheitswert",
"\n \"x\": {\"value\": 1, \"unit\": \"ja/nein\", \"comment\": \"Wahrheitswert\"}", "10feffff0108", "00",
"vvvnj"},
{"x,,bi3:2,0=off;1=on,ja/nein,Wahrheitswert", "\n \"0\": {\"name\": \"x\", \"value\": 1}", "10feffff0108", "00",
"nj"},
{"x,,bi3:2,0=off;1=on,ja/nein,Wahrheitswert", "\n \"x\": {\"value\": 1, \"unit\": \"ja/nein\", \"comment\": \"Wahrheitswert\"}", "10feffff0108", "00", "vvvnj"},
{"x,,bi3:2,0=off;1=on,ja/nein,Wahrheitswert", "\n \"0\": {\"name\": \"x\", \"value\": 1}", "10feffff0108", "00", "nj"},
{"x,,uch,1=test;2=high;3=off;0x10=on", "on", "10feffff0110", "00", ""},
{"x,s,uch", "3", "1050ffff00", "0103", ""},
{"x,,d2b,,°C,Aussentemperatur", "x=18.004 °C [Aussentemperatur]", "10fe0700090112", "00", "vvv"},
@@ -468,10 +501,14 @@ int main() {
{"x,,temp,,,,y,,d1c", "18.004;9.5", "10fe070003011213", "00", ""}, // reference to template, normal def
{"x,,temp;HEX:2", "18.004;13 14", "10fe07000401121314", "00", ""}, // reference to template and base type
{"x,,temp;HEX:2", "temp=18.004;=13 14", "10fe07000401121314", "00", "v"}, // reference to template and base type
// reference to template and base type
{"x,,temp:degrees;HEX:2", "degrees=18.004;=13 14", "10fe07000401121314", "00", "v"},
{"x,,temp:degrees;HEX:2", "degrees=18.004;=13 14", "10fe07000401121314", "00", "v"}, // reference to template and base type
};
DataFieldTemplates* templates = new DataFieldTemplates();
unsigned int lineNo = 0;
istringstream dummystr("#");
string errorDescription;
vector<string> row;
templates->readLineFromStream(dummystr, errorDescription, "inline", lineNo, row);
DataField* fields = NULL;
for (size_t i = 0; i < sizeof(checks) / sizeof(checks[0]); i++) {
string check[5] = checks[i];
@@ -514,18 +551,34 @@ int main() {
bool numeric = flags.find('n') != string::npos;
bool isTemplate = flags.find('t') != string::npos;
string item;
vector<string> entries;
while (getline(isstr, item, FIELD_SEPARATOR))
entries.push_back(item);
if (fields != NULL) {
delete fields;
fields = NULL;
}
vector<string>::iterator it = entries.begin();
result = DataField::create(it, entries.end(), templates, fields, isSet, isTemplate,
!isTemplate && (mstr[1] == BROADCAST || isMaster(mstr[1])));
if (isTemplate) {
lineNo = baseLine + i;
result = templates->readLineFromStream(isstr, errorDescription, "inline", lineNo, row, false);
if (result != RESULT_OK) {
cout << "\"" << check[0] << "\": template read error: " << getResultCode(result) << ", "
<< errorDescription << endl;
error = true;
}
continue;
}
TestReader reader{templates, isSet, mstr[1] == BROADCAST || isMaster(mstr[1])};
lineNo = 0;
dummystr = istringstream("#");
result = reader.readLineFromStream(dummystr, errorDescription, "inline", lineNo, row);
if (result != RESULT_OK) {
cout << "\"" << check[0] << "\": reader header error: " << getResultCode(result) << ", " << errorDescription
<< endl;
error = true;
continue;
}
lineNo = baseLine + i;
result = reader.readLineFromStream(isstr, errorDescription, "", lineNo, row);
fields = reader.m_fields;
if (failedCreate) {
if (result == RESULT_OK) {
cout << "\"" << check[0] << "\": failed create error: unexpectedly succeeded" << endl;
@@ -536,7 +589,7 @@ int main() {
continue;
}
if (result != RESULT_OK) {
cout << "\"" << check[0] << "\": create error: " << getResultCode(result) << endl;
cout << "\"" << check[0] << "\": create error: " << getResultCode(result) << ", " << errorDescription << endl;
error = true;
continue;
}
@@ -545,26 +598,9 @@ int main() {
error = true;
continue;
}
if (it != entries.end()) {
cout << "\"" << check[0] << "\": create error: trailing input" << endl;
error = true;
continue;
}
cout << "\"" << check[0] << "\"=\"";
fields->dump(cout);
cout << "\": create OK" << endl;
if (isTemplate) {
// store new template
result = templates->add(fields, "", true);
if (result == RESULT_OK) {
fields = NULL;
cout << " store template OK" << endl;
} else {
cout << " store template error: " << getResultCode(result) << endl;
error = true;
}
continue;
}
ostringstream output;
MasterSymbolString writeMstr;
+218 -32
View File
@@ -47,50 +47,236 @@ void verify(bool expectFailMatch, string type, string input,
}
}
int main() {
istringstream ifs(
"line 1 col 1,line 1 col 2,line 1 col 3\n"
"line 2 col 1,\"line 2 col 2\",\"line 2 \"\"col 3\"\"\"\n"
"line 4 col 1,\"line 4 col 2 part 1\n"
"line 4 col 2 part 2\",line 4 col 3\n"
",,,\n"
"line 6 col 1,,line 6 col 3\n"
"line 8 col 1,\"line 8 col 2 part 1;\n"
"line 8 col 2 part 2\",line 8 col 3\n"
);
string resultlines[][3] = {
{"line 1 col 1", "line 1 col 2", "line 1 col 3"},
{"line 2 col 1", "line 2 col 2", "line 2 \"col 3\""},
{"", "", ""},
{"line 4 col 1", "line 4 col 2 part 1;line 4 col 2 part 2", "line 4 col 3"},
{"", "", ""},
{"line 6 col 1", "", "line 6 col 3"},
{"", "", ""},
{"line 8 col 1", "line 8 col 2 part 1;line 8 col 2 part 2", "line 8 col 3"},
};
unsigned int lineNo = 0;
vector<string> row;
string resultlines[][3] = {
{"col 1", "col 2", "col 3"},
{"line 2 col 1", "line 2 col 2", "line 2 \"col 3\";default of col 3"},
{"", "", ""},
{"line 4 col 1", "line 4 col 2 part 1;line 4 col 2 part 2", "line 4 col 3;default of col 3"},
{"", "", ""},
{"line 6 col 1", "", "line 6 col 3;default of col 3"},
{"", "", ""},
{"line 8 col 1", "line 8 col 2 part 1;line 8 col 2 part 2", "line 8 col 3;default of col 3"},
};
while (FileReader::splitFields(ifs, row, lineNo)) {
cout << "line " << static_cast<unsigned>(lineNo) << ": split OK" << endl;
string resultline[3] = resultlines[lineNo-1];
string resultsublines[][2][4] = {
{},
{{"subcol 1", "line 2 subcol 1", "subcol 2", "line 2 subcol 2;default of sub 0 subcol 2"},{"subcol 2", "line 2 subcol 2", "subcol 3", "line 2 subcol 3"}},
{},
{{"subcol 1", "line 4 subcol 1", "subcol 2", "line 4 subcol 2;default of sub 0 subcol 2"},{"subcol 2", "line 4 subcol 2", "subcol 3", "line 4 subcol 3"}},
{},
{{"subcol 1", "line 6 subcol 1", "subcol 2", "line 6 subcol 2;default of sub 0 subcol 2"},{"subcol 2", "line 6 subcol 2", "subcol 3", "line 6 subcol 3"}},
{},
{{"subcol 1", "line 8 subcol 1", "subcol 2", "line 8 subcol 2;default of sub 0 subcol 2"},{"subcol 2", "line 8 subcol 2", "subcol 3", "line 8 subcol 3"}},
};
static unsigned int baseLine = 0;
class NoopReader : public FileReader {
public:
result_t addFromFile(vector<string>& row, string& errorDescription,
const string filename, unsigned int lineNo) override {
return RESULT_OK;
}
};
class TestReader : public MappedFileReader {
public:
TestReader(size_t expectedCols) : MappedFileReader::MappedFileReader(false), m_expectedCols(expectedCols) {}
result_t getFieldMap(vector<string>& row, string& errorDescription) override {
if (row.size() == m_expectedCols) {
cout << "get field map: split OK" << endl;
return RESULT_OK;
}
cout << "get field map: error got " << static_cast<unsigned>(row.size()) << " columns, expected " <<
static_cast<unsigned>(m_expectedCols) << endl;
return RESULT_ERR_EOF;
}
result_t addFromFile(map<string, string>& row, vector< map<string, string> >& subRows,
string& errorDescription, const string filename, unsigned int lineNo) override {
if (row.empty() || (m_expectedCols == 3) != subRows.empty()) {
cout << "read line " << static_cast<unsigned>(baseLine + lineNo) << ": read error: got "
<< static_cast<unsigned>(row.size()) << "/3 main, " << static_cast<unsigned>(subRows.size())
<< (m_expectedCols == 3 ? "/0 sub" : "/>0 sub") << endl;
return RESULT_ERR_EOF;
}
if (lineNo < 2 || lineNo >= 1+sizeof(resultlines)/sizeof(string[3])) {
cout << "read line " << static_cast<unsigned>(baseLine + lineNo) << ": error invalid line" << endl;
return RESULT_ERR_INVALID_ARG;
}
cout << "read line " << static_cast<unsigned>(baseLine + lineNo) << ": split OK" << endl;
string resultline[3] = resultlines[lineNo - 1];
if (row.empty()) {
cout << " result empty";
if (resultline[0] == "") {
cout << ": OK" << endl;
} else {
cout << ": error" << endl;
return RESULT_ERR_INVALID_ARG;
}
return RESULT_EMPTY;
}
bool error = false;
string colnames[3] = resultlines[0];
map<string, string>& defaults = getDefaults()[""];
for (size_t colIdx = 0; colIdx < 3; colIdx++) {
string col = colnames[colIdx];
string got = row[col] + defaults[col];
string expect = resultline[colIdx];
ostringstream type;
type << "line " << static_cast<unsigned>(baseLine + lineNo) << " column \"" << col << "\"";
bool match = got == expect;
verify(false, type.str(), expect, match, expect, got);
if (!match) {
error = true;
}
continue;
}
for (vector<string>::iterator it = row.begin(); it != row.end(); it++) {
string got = *it;
string expect = resultline[distance(row.begin(), it)];
if (row.size() > 3) {
ostringstream type;
type << "line " << static_cast<unsigned>(lineNo) << " col " << static_cast<size_t>(distance(row.begin(), it)+1);
verify(false, type.str(), expect, got == expect, expect, got);
type << "line " << static_cast<unsigned>(baseLine + lineNo);
verify(false, type.str(), "", false, "", "extra column");
error = true;
}
for (size_t subIdx = 0; subIdx < subRows.size(); subIdx++) {
string resultsubline[4] = resultsublines[lineNo - 1][subIdx];
row = subRows[subIdx];
if (row.empty()) {
cout << " sub " << subIdx << " result empty";
if (resultline[0] == "") {
cout << ": OK" << endl;
} else {
cout << ": error" << endl;
return RESULT_ERR_INVALID_ARG;
}
return RESULT_EMPTY;
}
vector< map<string, string> >& subDefaults = getSubDefaults()[""];
for (size_t colIdx = 0; colIdx < 2; colIdx++) {
string col = resultsubline[colIdx*2];
string got = row[col];
if (subIdx < subDefaults.size()) {
got += subDefaults[subIdx][col];
}
string expect = resultsubline[colIdx*2+1];
ostringstream type;
type << "line " << static_cast<unsigned>(baseLine + lineNo) << " sub " << subIdx << " column \"" << col << "\"";
bool match = got == expect;
verify(false, type.str(), expect, match, expect, got);
if (!match) {
error = true;
}
}
if (row.size() > 2) {
ostringstream type;
type << "line " << static_cast<unsigned>(baseLine + lineNo) << " sub " << subIdx;
verify(false, type.str(), "", false, "", "extra sub column");
error = true;
}
}
return error ? RESULT_ERR_INVALID_ARG : RESULT_OK;
}
private:
size_t m_expectedCols;
};
int main(int argc, char** argv) {
if (argc > 1) {
NoopReader reader;
for (int argpos = 1; argpos < argc; argpos++) {
size_t hash = 0, size = 0;
time_t time = 0;
string errorDescription;
result_t result = reader.readFromFile(argv[argpos], errorDescription, false, NULL, &hash, &size, &time);
cout << argv[argpos] << " ";
if (result != RESULT_OK) {
cout << getResultCode(result) << ", " << errorDescription << endl;
error = true;
continue;
}
FileReader::formatHash(hash, cout);
cout << " " << size << " " << time << endl;
}
return error ? 1 : 0;
}
baseLine = __LINE__+1;
istringstream ifs(
"col 1,col 2,col 3\n"
"line 2 col 1,\"line 2 col 2\",\"line 2 \"\"col 3\"\";default of col 3\"\n"
"line 4 col 1,\"line 4 col 2 part 1\n"
"line 4 col 2 part 2\",line 4 col 3;default of col 3\n"
",,,\n"
"line 6 col 1,,line 6 col 3;default of col 3\n"
"line 8 col 1,\"line 8 col 2 part 1;\n"
"line 8 col 2 part 2\",line 8 col 3;default of col 3\n"
);
size_t hash = 0, size = 0, expectHash = 0xfd58724c2984595d, expectSize = 301;
TestReader reader{3};
unsigned int lineNo = 0;
vector<string> row;
string errorDescription;
while (ifs.peek() != EOF) {
istringstream str;
result_t result = reader.readLineFromStream(ifs, errorDescription, "", lineNo, row, true, &hash, &size);
if (result != RESULT_OK) {
cout << " error " << getResultCode(result) << endl;
error = true;
}
}
if (hash == expectHash) {
cout << "hash OK" << endl;
} else {
cout << "hash error: got 0x" << hex << hash << ", expected 0x" << expectHash << dec << endl;
error = true;
}
if (size == expectSize) {
cout << "size OK" << endl;
} else {
cout << "size error: got " << size << ", expected " << expectSize << endl;
error = true;
}
ifs.clear();
baseLine = __LINE__+1;
ifs.str(
"col 1,col 2,col 3,*subcol 1,subcol 2,*subcol 2,subcol 3\n"
"line 2 col 1,\"line 2 col 2\",\"line 2 \"\"col 3\"\"\",line 2 subcol 1,line 2 subcol 2,line 2 subcol 2,line 2 subcol 3\n"
"line 4 col 1,\"line 4 col 2 part 1\n"
"line 4 col 2 part 2\",line 4 col 3,line 4 subcol 1,line 4 subcol 2,line 4 subcol 2,line 4 subcol 3\n"
",,,\n"
"line 6 col 1,,line 6 col 3,line 6 subcol 1,line 6 subcol 2,line 6 subcol 2,line 6 subcol 3\n"
"line 8 col 1,\"line 8 col 2 part 1;\n"
"line 8 col 2 part 2\",line 8 col 3,line 8 subcol 1,line 8 subcol 2,line 8 subcol 2,line 8 subcol 3\n"
);
hash = 0, size = 0, expectHash = 0xec31914e32c6fb6f, expectSize = 527;
TestReader reader2{7};
lineNo = 0;
map<string, string> defaults;
reader2.getDefaults("")["col 3"] = ";default of col 3";
vector< map<string, string> >& subDefaults = reader2.getSubDefaults("");
subDefaults.resize(1);
subDefaults[0]["subcol 2"] = ";default of sub 0 subcol 2";
while (ifs.peek() != EOF) {
istringstream str;
result_t result = reader2.readLineFromStream(ifs, errorDescription, "", lineNo, row, true, &hash, &size);
if (result != RESULT_OK) {
cout << " error " << getResultCode(result) << endl;
error = true;
}
}
if (hash == expectHash) {
cout << "hash OK" << endl;
} else {
cout << "hash error: got 0x" << hex << hash << ", expected 0x" << expectHash << dec << endl;
error = true;
}
if (size == expectSize) {
cout << "size OK" << endl;
} else {
cout << "size error: got " << size << ", expected " << expectSize << endl;
error = true;
}
return error ? 1 : 0;
+129 -205
View File
@@ -25,11 +25,16 @@
#include "lib/ebus/message.h"
using namespace ebusd;
using std::cout;
using std::endl;
static bool error = false;
void verify(bool expectFailMatch, string type, string input,
bool match, string expectStr, string gotStr) {
if (expectFailMatch) {
if (match) {
error = true;
cout << " failed " << type << " match >" << input
<< "< error: unexpectedly succeeded" << endl;
} else {
@@ -38,6 +43,7 @@ void verify(bool expectFailMatch, string type, string input,
} else if (match) {
cout << " " << type << " match >" << input << "< OK" << endl;
} else {
error = true;
cout << " " << type << " match >" << input << "< error: got >"
<< gotStr << "<, expected >" << expectStr << "<" << endl;
}
@@ -46,6 +52,7 @@ void verify(bool expectFailMatch, string type, string input,
DataFieldTemplates* templates = NULL;
namespace ebusd {
DataFieldTemplates* getTemplates(const string filename) {
if (filename == "") { // avoid compiler warning
return templates;
@@ -59,8 +66,9 @@ int main() {
// field: name,part,type[:len][,[divisor|values][,[unit][,[comment]]]]
// template: name,type[:len][,[divisor|values][,[unit][,[comment]]]]
// condition: name,circuit,messagename,[comment],[fieldname],[ZZ],values
// "message", "decoded", "master", "slave", "flags"
unsigned int baseLine = __LINE__+1;
string checks[][5] = {
// "message", "decoded", "master", "slave", "flags"
{"date,HDA:3,,,Datum", "", "", "", "template"},
{"time,VTI,,,", "", "", "", "template"},
{"dcfstate,UCH,0=nosignal;1=ok;2=sync;3=valid,,", "", "", "", "template"},
@@ -73,103 +81,75 @@ int main() {
{"pumpstate,UCH,0=off;1=on;2=overrun,,Pumpenstatus", "", "", "", "template"},
{"tempsensor,temp;sensor,,Temperatursensor", "", "", "", "template"},
{"tempsensorc,temp;sensorc,,Temperatursensor", "", "", "", "template"},
{"r,,Status01,VL/RL/AussenTemp/VLWW/SpeicherTemp/Status,,08,B511,01,,,temp1;temp1;temp2;temp1;temp1;pumpstate",
"28.0;24.0;4.938;35.0;41.0;4", "ff08b5110101", "093830f00446520400ff", "d"},
{"r,message circuit,message name,message comment,,25,B509,0d2800,,,tempsensor",
"temp=-14.00 Temperatursensor [Temperatur];sensor=ok [Fühlerstatus]", "ff25b509030d2800", "0320ff00", "mD"},
{"r,message circuit,message name,message comment,,25,B509,0d2800,,,tempsensor,,field unit,field comment",
"temp=-14.00 field unit [field comment];sensor=ok [Fühlerstatus]", "ff25b509030d2800", "0320ff00", "mD"},
{"r,message circuit,message name,message comment,,25,B509,0d2800,,,tempsensor,,field unit,field comment",
"\n \"temp\": {\"value\": -14.00},\n \"sensor\": {\"value\": \"ok\"}", "ff25b509030d2800", "0320ff00",
"mj"},
{"r,message circuit,message name,message comment,,25,B509,0d2800,,,tempsensor,,field unit,field comment",
"\n \"temp\": {\"value\": -14.00, \"unit\": \"field unit\", \"comment\": \"field comment\"},\n"
" \"sensor\": {\"value\": \"ok\", \"comment\": \"Fühlerstatus\"}", "ff25b509030d2800", "0320ff00", "mJ"},
{"r,message circuit,message name,message comment,,25,B509,0d2800,,,temp,,field unit,field comment,,,sensor",
"temp=-14.00 field unit [field comment];sensor=ok [Fühlerstatus]", "ff25b509030d2800", "0320ff00", "mD"},
{"r,message circuit,message name,message comment,,25,B509,0d2800,,,D2C,,°C,Temperatur,,,sensor",
"\n \"0\": {\"name\": \"\", \"value\": -14.00},\n \"1\": {\"name\": \"sensor\", \"value\": \"ok\"}",
"ff25b509030d2800", "0320ff00", "mj"},
{"r,,name,,,25,B509,0d2800,,,tempsensorc", "-14.00", "ff25b509030d2800", "0320ff55", "m"},
{"r,,name,,,25,B509,0d28,,m,sensorc,,,,,,temp", "-14.00", "ff25b509030d2855", "0220ff", "m"},
{"r,,Status01,VL/RL/AussenTemp/VLWW/SpeicherTemp/Status,,08,B511,01,,,temp1;temp1;temp2;temp1;temp1;pumpstate", "28.0;24.0;4.938;35.0;41.0;4", "ff08b5110101", "093830f00446520400ff", "d"},
{"r,message circuit,message name,message comment,,25,B509,0d2800,,,tempsensor", "temp=-14.00 Temperatursensor [Temperatur];sensor=ok [Fühlerstatus]", "ff25b509030d2800", "0320ff00", "D"},
{"r,message circuit,message name,message comment,,25,B509,0d2800,,,tempsensor,,field unit,field comment", "temp=-14.00 field unit [field comment];sensor=ok [Fühlerstatus]", "ff25b509030d2800", "0320ff00", "D"},
{"r,message circuit,message name,message comment,,25,B509,0d2800,,,tempsensor,,field unit,field comment", "\n \"temp\": {\"value\": -14.00},\n \"sensor\": {\"value\": \"ok\"}", "ff25b509030d2800", "0320ff00", "j"},
{"r,message circuit,message name,message comment,,25,B509,0d2800,,,tempsensor,,field unit,field comment", "\n \"temp\": {\"value\": -14.00, \"unit\": \"field unit\", \"comment\": \"field comment\"},\n" " \"sensor\": {\"value\": \"ok\", \"comment\": \"Fühlerstatus\"}", "ff25b509030d2800", "0320ff00", "J"},
{"r,message circuit,message name,message comment,,25,B509,0d2800,,,temp,,field unit,field comment,,,sensor", "temp=-14.00 field unit [field comment];sensor=ok [Fühlerstatus]", "ff25b509030d2800", "0320ff00", "D"},
{"r,message circuit,message name,message comment,,25,B509,0d2800,,,D2C,,°C,Temperatur,,,sensor", "\n \"0\": {\"name\": \"\", \"value\": -14.00},\n \"1\": {\"name\": \"sensor\", \"value\": \"ok\"}", "ff25b509030d2800", "0320ff00", "j"},
{"r,,name,,,25,B509,0d2800,,,tempsensorc", "-14.00", "ff25b509030d2800", "0320ff55", ""},
{"r,,name,,,25,B509,0d28,,m,sensorc,,,,,,temp", "-14.00", "ff25b509030d2855", "0220ff", ""},
{"u,,first,,,fe,0700,,x,,bda", "26.10.2014", "fffe07000426100614", "00", "p"},
{"u,broadcast,hwStatus,,,fe,b505,27,,,UCH,,,,,,UCH,,,,,,UCH,,,", "0;19;0", "10feb505042700130097", "00", ""},
{"w,,first,,,15,b509,0400,date,,bda", "26.10.2014", "ff15b50906040026100614", "00", "m"},
{"w,,first,,,15,b509", "", "ff15b50900", "00", "m"},
{"w,,,,,,b505,2d", "", "", "", "defaults"},
{"w,,offset,,,50,,,,,temp", "0.50", "ff50b505042d080000", "00", "md"},
{"r,ehp,time,,,08,b509,0d2800,,,time", "15:00:17", "ff08b509030d2800", "0311000f", "md"},
{"w,,first,,,15,b509,0400,date,,bda", "26.10.2014", "ff15b50906040026100614", "00", ""},
{"w,,first,,,15,b509", "", "ff15b50900", "00", ""},
{"*w,,,,,,b505,2d", "", "", "", ""},
{"w,,offset,,,50,,,,,temp", "0.50", "ff50b505042d080000", "00", "kd"},
{"r,ehp,time,,,08,b509,0d2800,,,time", "15:00:17", "ff08b509030d2800", "0311000f", "d"},
{"r,ehp,time,,,08;10,b509,0d2800,,,time", "", "", "", "c"},
{"r,ehp,time,,,08;09,b509,0d2800,,,time", "15:00:17", "ff08b509030d2800", "0311000f", "md*"},
{"r,ehp,date,,,08,b509,0d2900,,,date", "23.11.2014", "ff08b509030d2900", "03170b0e", "md"},
{"r,700,date,,,15,b524,020000003400,,,IGN:4,,,,,,date", "23.11.2015", "ff15b52406020000003400", "0703003400170b0f",
"d"},
{"r,700,time,,,15,b524,030000003500,,,IGN:4,,,,,,HTI", "12:29:06", "ff15b52406030000003500", "07030035000c1d06",
"d"},
{"", "23.11.2015", "ff15b52406020000003400", "0703003400170b0f", "d"},
{"", "12:29:06", "ff15b52406030000003500", "07030035000c1d06", "d"},
{"w,700,date,,,15,b524,020000003400,,,date", "23.11.2015", "ff15b52409020000003400170b0f", "00", "m"},
{"r,ehp,error,,,08,b509,0d2800,index,m,UCH,,,,,,time", "3;15:00:17", "ff08b509040d280003", "0311000f", "mdi"},
{"r,ehp,error,,,08,b509,0d2800,index,m,UCH,,,,,,time", "index=3;time=15:00:17", "ff08b509040d280003", "0311000f",
"mD"},
{"u,ehp,ActualEnvironmentPower,Energiebezug,,08,B509,29BA00,,s,IGN:2,,,,,s,power", "8", "1008b5090329ba00",
"03ba0008", "pm"},
{"uw,ehp,test,Test,,08,B5de,ab,,,power,,,,,s,hex:1", "8;39", "1008b5de02ab08", "0139", "pm"},
{"r,ehp,time,,,08;09,b509,0d2800,,,time", "15:00:17", "ff08b509030d2800", "0311000f", "d*"},
{"r,ehp,date,,,08,b509,0d2900,,,date", "23.11.2014", "ff08b509030d2900", "03170b0e", "d"},
{"r,700,date,,,15,b524,020000003400,,,IGN:4,,,,,,date", "23.11.2015", "ff15b52406020000003400", "0703003400170b0f", "d"},
{"", "23.11.2015", "ff15b52406020000003400", "0703003400170b0f", "kd"},
{"r,700,time,,,15,b524,030000003500,,,IGN:4,,,,,,HTI", "12:29:06", "ff15b52406030000003500", "07030035000c1d06", "d"},
{"", "12:29:06", "ff15b52406030000003500", "07030035000c1d06", "kd"},
{"w,700,date,,,15,b524,020000003400,,,date", "23.11.2015", "ff15b52409020000003400170b0f", "00", ""},
{"r,ehp,error,,,08,b509,0d2800,index,m,UCH,,,,,,time", "3;15:00:17", "ff08b509040d280003", "0311000f", "di"},
{"r,ehp,error,,,08,b509,0d2800,index,m,UCH,,,,,,time", "index=3;time=15:00:17", "ff08b509040d280003", "0311000f", "D"},
{"u,ehp,ActualEnvironmentPower,Energiebezug,,08,B509,29BA00,,s,IGN:2,,,,,s,power", "8", "1008b5090329ba00", "03ba0008", "p"},
{"uw,ehp,test,Test,,08,B5de,ab,,,power,,,,,s,hex:1", "8;39", "1008b5de02ab08", "0139", "p"},
{"u,ehp,hwTankTemp,Speichertemperatur IST,,25,B509,290000,,,IGN:2,,,,,,tempsensor", "", "", "", "M"},
{"", "55.50;ok", "1025b50903290000", "050000780300", "d"},
{"r,ehp,datetime,Datum Uhrzeit,,50,B504,00,,,dcfstate,,,,time,,BTI,,,,date,,BDA,,,,temp,,temp2",
"valid;08:24:51;31.12.2014;-0.875", "1050b5040100", "0a035124083112031420ff", "md" },
{"r,ehp,bad,invalid pos,,50,B5ff,000102,,m,HEX:8;tempsensor;tempsensor;tempsensor;tempsensor;power;power,,,", "",
"", "", "c" },
{"r,ehp,bad,invalid pos,,50,B5ff,,,s,HEX:8;tempsensor;tempsensor;tempsensor;tempsensor;tempsensor;power;power,,,",
"", "", "", "c" },
{"", "55.50;ok", "1025b50903290000", "050000780300", "kd"},
{"r,ehp,datetime,Datum Uhrzeit,,50,B504,00,,,dcfstate,,,,time,,BTI,,,,date,,BDA,,,,temp,,temp2", "valid;08:24:51;31.12.2014;-0.875", "1050b5040100", "0a035124083112031420ff", "d" },
{"r,ehp,bad,invalid pos,,50,B5ff,000102,,m,HEX:8;tempsensor;tempsensor;tempsensor;tempsensor;power;power,,,", "", "", "", "c" },
{"r,ehp,bad,invalid pos,,50,B5ff,,,s,HEX:8;tempsensor;tempsensor;tempsensor;tempsensor;tempsensor;power;power,,,", "", "", "", "c" },
{"r,ehp,ApplianceCode,,,08,b509,0d4301,,,UCH,", "9", "ff08b509030d4301", "0109", "d" },
{"r,ehp,,,,08,b509,0d", "", "", "", "defaults" },
{"w,ehp,,,,08,b509,0e", "", "", "", "defaults" },
{"[brinetowater],ehp,ApplianceCode,,,,4;6;8;9;10", "", "", "", "condition" },
{"[airtowater]r,ehp,notavailable,,,,,0100,,,uch", "1", "", "", "c" },
{"[brinetowater]r,ehp,available,,,,,0100,,,uch", "1", "ff08b509030d0100", "0101", "d" },
{"*r,ehp,,,,08,b509,0d", "", "", "", "" },
{"*w,ehp,,,,08,b509,0e", "", "", "", "" },
{"*[brinetowater],ehp,ApplianceCode,,,,4;6;8;9;10", "", "", "", "" },
{"[airtowater]r,ehp,notavailable,,,,,0100,,,uch", "1", "", "", "kc" },
{"[brinetowater]r,ehp,available,,,,,0100,,,uch", "1", "ff08b509030d0100", "0101", "kd" },
{"r,,x,,,,,\"6800\",,,UCH,,,bit0=\"comment, continued comment", "", "", "", "c" },
{"r,,x,,,,,\"6800\",,,UCH,,\"\",\"bit0=\"comment, continued comment\"", "=1 [bit0=\"comment, continued comment]",
"ff08b509030d6800", "0101", "mD" },
{"r,ehp,multi,,,,,0001:5;0002;0003,longname,,STR:15", "ABCDEFGHIJKLMNO",
"ff08b509030d0001;ff08b509030d0003;ff08b509030d0002", "054142434445;054b4c4d4e4f;05464748494a", "mdC" },
{"r,ehp,multi,,,,,01;02;03,longname,,STR:15", "ABCDEFGHIJKLMNO", "ff08b509020d01;ff08b509020d03;ff08b509020d02",
"084142434445464748;054b4c4d4e4f;02494a", "mdC" },
{"w,ehp,multi,,,,,01:8;02:2;03,longname,,STR:15", "ABCDEFGHIJKLMNO",
"ff08b5090a0e014142434445464748;ff08b509040e02494a;ff08b509070e034b4c4d4e4f", "00;00;00", "mdC" },
{"w,ehp,multi,,,,,01:8;02:2;0304,longname,,STR:15", "ABCDEFGHIJKLMNO",
"ff08b5090a0e014142434445464748;ff08b509040e02494a;ff08b509070e034b4c4d4e4f", "00;00;00", "cC" },
{"r,ehp,scan,chained scan,,08,B509,24:9;25;26;27,,,IGN,,,,id4,,STR:28", "21074500100027790000000000N8",
"ff08b5090124;ff08b5090125;ff08b5090126;ff08b5090127",
"09003231303734353030;09313030303237373930;09303030303030303030;024E38", "mdC" },
{"r,,x,,,,,6900,,,UCH,10,bar,,Bit7,,BI7:1,0=B70;1=B71,,,Bit6,,BI6:1,0=B60;1=B61", "1.9;B71;B61",
"ff08b509030d6900", "03138040", "md" },
{"r,,x,,,,,6900,,,UCH,10,bar,,Bit7,,BI7:1,0=B70;1=B71,,,Bit6,,BI6:1,0=B60;1=B61", "1.9;B71;B60",
"ff08b509030d6900", "0313ffbf", "md" },
{"r,,x,,,,,6900,,,UCH,10,bar,,Bit7,,BI7:1,0=B70;1=B71,,,Bit6,,BI6:1,0=B60;1=B61", "1.9;B70;B61",
"ff08b509030d6900", "03137fff", "md" },
{"r,,x,,,,,6900,,,UCH,10,bar,,Bit7,,BI7:1,0=B70;1=B71,,,Bit6,,BI6:1,0=B60;1=B61", "1.9;B70;B60",
"ff08b509030d6900", "03137fbf", "md" },
{"r,,x,,,,,6a00,,,UCH,10,bar,,Bit6,,BI6:1,0=B60;1=B61,,,Bit7,,BI7:1,0=B70;1=B71", "1.9;B61;B71",
"ff08b509030d6900", "0213ff", "md" },
{"r,,x,,,,,6a00,,,UCH,10,bar,,Bit6,,BI6:1,0=B60;1=B61,,,Bit7,,BI7:1,0=B70;1=B71", "1.9;B60;B71",
"ff08b509030d6900", "0213bf", "md" },
{"r,,x,,,,,6a00,,,UCH,10,bar,,Bit6,,BI6:1,0=B60;1=B61,,,Bit7,,BI7:1,0=B70;1=B71", "1.9;B61;B70",
"ff08b509030d6900", "02137f", "md" },
{"r,,x,,,,,6a00,,,UCH,10,bar,,Bit6,,BI6:1,0=B60;1=B61,,,Bit7,,BI7:1,0=B70;1=B71", "1.9;B60;B70",
"ff08b509030d6900", "02133f", "md" },
{"r,cir*cuit#level,na*me,com*ment,ff,75,b509,0d", "", "", "", "defaults" },
{"r,CIRCUIT,NAME,COMMENT,,,,0100,field,,UCH",
"r,cirCIRCUITcuit,naNAMEme,comCOMMENTment,ff,75,b509,0d0100,field,s,UCH,,,: field=42",
"ff08b509030d0100", "012a", "mDN"},
{"r,,x,,,,,\"6800\",,,UCH,,\"\",\"bit0=\"comment, continued comment\"", "=1 [bit0=\"comment, continued comment]", "ff08b509030d6800", "0101", "D" },
{"r,ehp,multi,,,,,0001:5;0002;0003,longname,,STR:15", "ABCDEFGHIJKLMNO", "ff08b509030d0001;ff08b509030d0003;ff08b509030d0002", "054142434445;054b4c4d4e4f;05464748494a", "dC" },
{"r,ehp,multi,,,,,01;02;03,longname,,STR:15", "ABCDEFGHIJKLMNO", "ff08b509020d01;ff08b509020d03;ff08b509020d02", "084142434445464748;054b4c4d4e4f;02494a", "dC" },
{"w,ehp,multi,,,,,01:8;02:2;03,longname,,STR:15", "ABCDEFGHIJKLMNO", "ff08b5090a0e014142434445464748;ff08b509040e02494a;ff08b509070e034b4c4d4e4f", "00;00;00", "dC" },
{"w,ehp,multi,,,,,01:8;02:2;0304,longname,,STR:15", "ABCDEFGHIJKLMNO", "ff08b5090a0e014142434445464748;ff08b509040e02494a;ff08b509070e034b4c4d4e4f", "00;00;00", "cC" },
{"r,ehp,scan,chained scan,,08,B509,24:9;25;26;27,,,IGN,,,,id4,,STR:28", "21074500100027790000000000N8", "ff08b5090124;ff08b5090125;ff08b5090126;ff08b5090127", "09003231303734353030;09313030303237373930;09303030303030303030;024E38", "dC" },
{"r,,x,,,,,6900,,,UCH,10,bar,,Bit7,,BI7:1,0=B70;1=B71,,,Bit6,,BI6:1,0=B60;1=B61", "1.9;B71;B61", "ff08b509030d6900", "03138040", "d" },
{"r,,x,,,,,6900,,,UCH,10,bar,,Bit7,,BI7:1,0=B70;1=B71,,,Bit6,,BI6:1,0=B60;1=B61", "1.9;B71;B60", "ff08b509030d6900", "0313ffbf", "d" },
{"r,,x,,,,,6900,,,UCH,10,bar,,Bit7,,BI7:1,0=B70;1=B71,,,Bit6,,BI6:1,0=B60;1=B61", "1.9;B70;B61", "ff08b509030d6900", "03137fff", "d" },
{"r,,x,,,,,6900,,,UCH,10,bar,,Bit7,,BI7:1,0=B70;1=B71,,,Bit6,,BI6:1,0=B60;1=B61", "1.9;B70;B60", "ff08b509030d6900", "03137fbf", "d" },
{"r,,x,,,,,6a00,,,UCH,10,bar,,Bit6,,BI6:1,0=B60;1=B61,,,Bit7,,BI7:1,0=B70;1=B71", "1.9;B61;B71", "ff08b509030d6a00", "0213ff", "d" },
{"r,,x,,,,,6a00,,,UCH,10,bar,,Bit6,,BI6:1,0=B60;1=B61,,,Bit7,,BI7:1,0=B70;1=B71", "1.9;B60;B71", "ff08b509030d6a00", "0213bf", "d" },
{"r,,x,,,,,6a00,,,UCH,10,bar,,Bit6,,BI6:1,0=B60;1=B61,,,Bit7,,BI7:1,0=B70;1=B71", "1.9;B61;B70", "ff08b509030d6a00", "02137f", "d" },
{"r,,x,,,,,6a00,,,UCH,10,bar,,Bit6,,BI6:1,0=B60;1=B61,,,Bit7,,BI7:1,0=B70;1=B71", "1.9;B60;B70", "ff08b509030d6a00", "02133f", "d" },
{"*r,cir*cuit#level,na*me,com*ment,ff,75,b509,0d", "", "", "", "" },
{"r,CIRCUIT,NAME,COMMENT,,,,0100,field,,UCH", "r,cirCIRCUITcuit,naNAMEme,comCOMMENTment,ff,75,b509,0d0100,field,s,UCH,,,: field=42", "ff75b509030d0100", "012a", "DN"},
};
templates = new DataFieldTemplates();
unsigned int lineNo = 0;
istringstream dummystr("#");
string errorDescription;
vector<string> row;
templates->readLineFromStream(dummystr, errorDescription, "inline", lineNo, row, false);
lineNo = 0;
MessageMap* messages = new MessageMap();
dummystr = istringstream("#");
messages->readLineFromStream(dummystr, errorDescription, "inline", lineNo, row, false);
vector< vector<string> > defaultsRows;
map<string, Condition*> &conditions = messages->getConditions();
Message* message = NULL;
vector<Message*> deleteMessages;
vector<MasterSymbolString*> mstrs;
vector<SlaveSymbolString*> sstrs;
mstrs.resize(1);
@@ -179,9 +159,7 @@ int main() {
string inputStr = check[1];
string flags = check[4];
bool isTemplate = flags == "template";
bool isCondition = flags == "condition";
bool isDefaults = isCondition || flags == "defaults";
bool dontMap = flags.find('m') != string::npos;
bool keepMessages = flags.find('k') != string::npos;
bool onlyMap = flags.find('M') != string::npos;
bool failedCreate = flags.find('c') != string::npos;
bool isChain = flags.find('C') != string::npos;
@@ -194,60 +172,31 @@ int main() {
bool multi = flags.find('*') != string::npos;
bool withInput = flags.find('i') != string::npos;
result_t result = RESULT_EMPTY;
vector<string> entries;
istringstream ifs(check[0]);
unsigned int lineNo = 0;
if (!FileReader::splitFields(ifs, entries, lineNo)) {
entries.clear();
}
istringstream isstr(check[0]);
lineNo = baseLine + i;
cout << "line " << (lineNo+1) << " ";
if (isTemplate) {
// store new template
DataField* fields = NULL;
vector<string>::iterator it = entries.begin();
result = DataField::create(it, entries.end(), templates, fields, false, true, false);
result = templates->readLineFromStream(isstr, errorDescription, "inline", lineNo, row);
if (result != RESULT_OK) {
cout << "\"" << check[0] << "\": template fields create error: " << getResultCode(result) << endl;
} else if (it != entries.end()) {
cout << "\"" << check[0] << "\": template fields create error: trailing input "
<< static_cast<unsigned>(entries.end()-it) << endl;
} else {
cout << "\"" << check[0] << "\": create template OK" << endl;
result = templates->add(fields, "", true);
if (result == RESULT_OK) {
cout << " store template OK" << endl;
} else {
cout << " store template error: " << getResultCode(result) << endl;
delete fields;
}
cout << "\"" << check[0] << "\": template read error: " << getResultCode(result) << ", " << errorDescription
<< endl;
error = true;
}
cout << "\"" << check[0] << "\": template read OK" << endl;
continue;
}
if (isDefaults) {
if (!keepMessages) {
messages->clear();
}
if (isstr.peek() == '*') {
// store defaults or condition
vector<string>::iterator it = entries.begin();
size_t oldSize = conditions.size();
result = messages->addDefaultFromFile(defaultsRows, entries, it, "", "", "", "no file", 1);
result = messages->readLineFromStream(isstr, errorDescription, "inline", lineNo, row);
if (result != RESULT_OK) {
cout << "\"" << check[0] << "\": defaults read error: " << getResultCode(result) << endl;
} else if (it != entries.end()) {
cout << "\"" << check[0] << "\": defaults read error: trailing input "
<< static_cast<unsigned>(entries.end()-it) << endl;
} else {
cout << "\"" << check[0] << "\": read defaults OK" << endl;
if (isCondition) {
if (conditions.size() == oldSize) {
cout << " create condition error" << endl;
} else {
result = messages->resolveConditions();
if (result != RESULT_OK) {
cout << " resolve conditions error: " << getResultCode(result) << " " << messages->getLastError()
<< endl;
} else {
cout << " resolve conditions OK" << endl;
}
}
}
cout << "\"" << check[0] << "\": default read error: " << getResultCode(result) << ", " << errorDescription << endl;
error = true;
continue;
}
cout << "\"" << check[0] << "\": default read OK" << endl;
continue;
}
if (isChain) {
@@ -260,10 +209,11 @@ int main() {
} else if (mstrs[pos] != NULL) {
delete mstrs[pos];
}
mstrs[pos] = new MasterSymbolString;
mstrs[pos] = new MasterSymbolString();
result = mstrs[pos]->parseHex(token);
if (result != RESULT_OK) {
cout << "\"" << check[0] << "\": parse \"" << token << "\" error: " << getResultCode(result) << endl;
error = true;
break;
}
pos++;
@@ -281,21 +231,24 @@ int main() {
result = sstrs[pos]->parseHex(token);
if (result != RESULT_OK) {
cout << "\"" << check[0] << "\": parse \"" << token << "\" error: " << getResultCode(result) << endl;
error = true;
break;
}
pos++;
}
if (result != RESULT_OK) {
error = true;
continue;
}
} else {
if (mstrs[0] != NULL) {
delete mstrs[0];
}
mstrs[0] = new MasterSymbolString;
mstrs[0] = new MasterSymbolString();
result = mstrs[0]->parseHex(check[2]);
if (result != RESULT_OK) {
cout << "\"" << check[0] << "\": parse \"" << check[2] << "\" error: " << getResultCode(result) << endl;
error = true;
continue;
}
if (sstrs[0] != NULL) {
@@ -305,95 +258,72 @@ int main() {
result = sstrs[0]->parseHex(check[3]);
if (result != RESULT_OK) {
cout << "\"" << check[0] << "\": parse \"" << check[3] << "\" error: " << getResultCode(result) << endl;
error = true;
continue;
}
}
if (deleteMessages.size() > 0) {
for (vector<Message*>::iterator it = deleteMessages.begin(); it != deleteMessages.end(); it++) {
Message* deleteMessage = *it;
delete deleteMessage;
}
deleteMessages.clear();
}
if (entries.size() == 0) {
if (isstr.peek() == EOF) {
message = messages->find(*mstrs[0]);
if (message == NULL) {
cout << "\"" << check[2] << "\": find error: NULL" << endl;
error = true;
continue;
}
cout << "\"" << check[2] << "\": find OK" << endl;
} else {
vector<string>::iterator it = entries.begin();
string types = *it;
Condition* condition = NULL;
result = messages->readConditions(types, "no file", condition);
if (result == RESULT_OK) {
*it = types;
result = Message::create(it, entries.end(), &defaultsRows, condition, "no file", templates, deleteMessages);
}
result = messages->readLineFromStream(isstr, errorDescription, "inline", lineNo, row);
if (failedCreate) {
if (result == RESULT_OK) {
cout << "\"" << check[0] << "\": failed create error: unexpectedly succeeded" << endl;
error = true;
} else {
cout << "\"" << check[0] << "\": failed create OK" << endl;
}
continue;
}
if (result != RESULT_OK) {
cout << "\"" << check[0] << "\": create error: "
<< getResultCode(result) << endl;
printErrorPos(cout, entries.begin(), entries.end(), it, "", 0, result);
cout << "\"" << check[0] << "\": create error: " << getResultCode(result) << ", " << errorDescription << endl;
error = true;
continue;
}
if (deleteMessages.size() == 0) {
if (messages->size() == 0) {
cout << "\"" << check[0] << "\": create error: NULL" << endl;
error = true;
continue;
}
if (it != entries.end()) {
cout << "\"" << check[0] << "\": create error: trailing input " << static_cast<unsigned>(entries.end()-it)
<< endl;
continue;
}
if (multi && deleteMessages.size() == 1) {
if (multi && messages->size() == 1) {
cout << "\"" << check[0] << "\": create error: single message instead of multiple" << endl;
error = true;
continue;
}
if (!multi && deleteMessages.size() > 1) {
if (!multi && messages->size() > 1) {
cout << "\"" << check[0] << "\": create error: multiple messages instead of single" << endl;
error = true;
continue;
}
cout << "\"" << check[0] << "\": create OK" << endl;
if (!dontMap) {
result_t result = RESULT_OK;
for (vector<Message*>::iterator it = deleteMessages.begin(); it != deleteMessages.end(); it++) {
Message* deleteMessage = *it;
result_t result = messages->add(deleteMessage);
if (result != RESULT_OK) {
cout << "\"" << check[0] << "\": add error: "
<< getResultCode(result) << endl;
break;
}
}
if (result != RESULT_OK) {
continue;
}
cout << " map OK" << endl;
message = deleteMessages.front();
deleteMessages.clear();
if (onlyMap) {
continue;
}
Message* foundMessage = messages->find(*mstrs[0]);
if (foundMessage == message) {
cout << " find OK" << endl;
} else if (foundMessage == NULL) {
cout << " find error: NULL" << endl;
} else {
cout << " find error: different" << endl;
}
if (onlyMap) {
continue;
}
deque<Message*> msgs = messages->findAll("", "", "*", false, true, true, true, true, false);
if (msgs.empty()) {
message = NULL;
cout << "\"" << check[0] << "\": create error: message not found" << endl;
error = true;
continue;
}
message = *msgs.begin();
Message* foundMessage = messages->find(*mstrs[0], false, true, true, true, false);
if (foundMessage == message) {
cout << " find OK" << endl;
} else if (foundMessage == NULL) {
cout << " find error: message not found by master " << mstrs[0]->getStr() << endl;
error = true;
continue;
} else {
message = deleteMessages.front();
cout << " find error: different" << endl;
error = true;
}
}
@@ -411,6 +341,7 @@ int main() {
if (result != RESULT_OK) {
cout << " \"" << check[2] << "\" / \"" << check[3] << "\": decode error: "
<< getResultCode(result) << endl;
error = true;
continue;
}
cout << " \"" << check[2] << "\" / \"" << check[3] << "\": decode OK" << endl;
@@ -424,6 +355,7 @@ int main() {
if (failedPrepare) {
if (result == RESULT_OK) {
cout << " \"" << inputStr << "\": failed prepare error: unexpectedly succeeded" << endl;
error = true;
} else {
cout << " \"" << inputStr << "\": failed prepare OK" << endl;
}
@@ -431,8 +363,8 @@ int main() {
}
if (result != RESULT_OK) {
cout << " \"" << inputStr << "\": prepare error: "
<< getResultCode(result) << endl;
cout << " \"" << inputStr << "\": prepare error: " << getResultCode(result) << endl;
error = true;
continue;
}
cout << " \"" << inputStr << "\": prepare OK" << endl;
@@ -442,14 +374,6 @@ int main() {
}
}
if (deleteMessages.size() > 0) {
for (vector<Message*>::iterator it = deleteMessages.begin(); it != deleteMessages.end(); it++) {
Message* deleteMessage = *it;
delete deleteMessage;
}
deleteMessages.clear();
}
delete templates;
delete messages;
for (vector<MasterSymbolString*>::iterator it = mstrs.begin(); it != mstrs.end(); it++) {
@@ -458,5 +382,5 @@ int main() {
for (vector<SlaveSymbolString*>::iterator it = sstrs.begin(); it != sstrs.end(); it++) {
delete *it;
}
return 0;
return error ? 1 : 0;
}
+19 -1
View File
@@ -19,6 +19,7 @@
#include <iostream>
#include <iomanip>
#include <string>
#include <unordered_map>
#include "lib/ebus/symbol.h"
using namespace std;
@@ -48,7 +49,6 @@ void verify(bool expectFailMatch, string type, string input,
int main(int argc, char** argv) {
MasterSymbolString mstr;
if (argc > 1) {
result_t result;
if (argc > 2 && strcmp("escaped", argv[1]) == 0) {
@@ -119,5 +119,23 @@ int main(int argc, char** argv) {
verify(false, "data size", "0427a90015a901", sstr.getDataSize() == 4, expectStr, gotStr);
}
int masterCnt = 0, slaveCnt = 0;
for (int i=0; i<256; i++) {
if (isMaster(i)) {
masterCnt++;
} else if (isValidAddress(i, false)) {
slaveCnt++;
}
}
if (masterCnt == 25) {
cout << "count master addresses OK" << endl;
} else {
cout << "count master addresses error: found " << dec << masterCnt << " instead of 25" << endl;
}
if (slaveCnt == 228) {
cout << "count slave addresses OK" << endl;
} else {
cout << "count slave addresses error: found " << dec << slaveCnt << " instead of 228" << endl;
}
return error ? 1 : 0;
}