From 2a348c208749d0036d3d7e199e3170ee2836ff3e Mon Sep 17 00:00:00 2001 From: john30 Date: Wed, 4 Apr 2018 15:49:48 +0200 Subject: [PATCH] aligned tests to latest changes --- src/lib/ebus/contrib/test/test_tem.cpp | 6 +++--- src/lib/ebus/test/test_data.cpp | 8 ++++---- src/lib/ebus/test/test_filereader.cpp | 14 +++++++++----- src/lib/ebus/test/test_message.cpp | 26 +++++++++++++++++++++----- 4 files changed, 37 insertions(+), 17 deletions(-) diff --git a/src/lib/ebus/contrib/test/test_tem.cpp b/src/lib/ebus/contrib/test/test_tem.cpp index df388042..25897da7 100755 --- a/src/lib/ebus/contrib/test/test_tem.cpp +++ b/src/lib/ebus/contrib/test/test_tem.cpp @@ -118,7 +118,7 @@ int main() { istringstream dummystr("#"); string errorDescription; vector row; - templates->readLineFromStream("inline", false, &dummystr, &lineNo, &row, &errorDescription, NULL, NULL); + templates->readLineFromStream(&dummystr, "inline", false, &lineNo, &row, &errorDescription, NULL, NULL); const DataField* fields = NULL; for (unsigned int i = 0; i < sizeof(checks) / sizeof(checks[0]); i++) { string check[5] = checks[i]; @@ -156,7 +156,7 @@ int main() { lineNo = 0; dummystr.clear(); dummystr.str("#"); - result = reader.readLineFromStream("inline", false, &dummystr, &lineNo, &row, &errorDescription, NULL, NULL); + result = reader.readLineFromStream(&dummystr, "inline", false, &lineNo, &row, &errorDescription, NULL, NULL); if (result != RESULT_OK) { cout << "\"" << check[0] << "\": reader header error: " << getResultCode(result) << ", " << errorDescription << endl; @@ -164,7 +164,7 @@ int main() { continue; } lineNo = baseLine + i; - result = reader.readLineFromStream(__FILE__, false, &isstr, &lineNo, &row, &errorDescription, NULL, NULL); + result = reader.readLineFromStream(&isstr, __FILE__, false, &lineNo, &row, &errorDescription, NULL, NULL); fields = reader.m_fields; if (result != RESULT_OK) { diff --git a/src/lib/ebus/test/test_data.cpp b/src/lib/ebus/test/test_data.cpp index bf109ca2..614fcb12 100755 --- a/src/lib/ebus/test/test_data.cpp +++ b/src/lib/ebus/test/test_data.cpp @@ -512,7 +512,7 @@ int main() { istringstream dummystr("#"); string errorDescription; vector row; - templates->readLineFromStream(__FILE__, false, &dummystr, &lineNo, &row, &errorDescription, NULL, NULL); + templates->readLineFromStream(&dummystr, __FILE__, false, &lineNo, &row, &errorDescription, NULL, NULL); const DataField* fields = NULL; for (unsigned int i = 0; i < sizeof(checks) / sizeof(checks[0]); i++) { string check[5] = checks[i]; @@ -567,7 +567,7 @@ int main() { } if (isTemplate) { lineNo = baseLine + i; - result = templates->readLineFromStream(__FILE__, false, &isstr, &lineNo, &row, &errorDescription, NULL, NULL); + result = templates->readLineFromStream(&isstr, __FILE__, false, &lineNo, &row, &errorDescription, NULL, NULL); if (result != RESULT_OK) { cout << "\"" << check[0] << "\": template read error: " << getResultCode(result) << ", " << errorDescription << endl; @@ -579,7 +579,7 @@ int main() { lineNo = 0; dummystr.clear(); dummystr.str("#"); - result = reader.readLineFromStream(__FILE__, false, &dummystr, &lineNo, &row, &errorDescription, NULL, NULL); + result = reader.readLineFromStream(&dummystr, __FILE__, false, &lineNo, &row, &errorDescription, NULL, NULL); if (result != RESULT_OK) { cout << "\"" << check[0] << "\": read header error: " << getResultCode(result) << ", " << errorDescription << endl; @@ -587,7 +587,7 @@ int main() { continue; } lineNo = baseLine + i; - result = reader.readLineFromStream("", false, &isstr, &lineNo, &row, &errorDescription, NULL, NULL); + result = reader.readLineFromStream(&isstr, "", false, &lineNo, &row, &errorDescription, NULL, NULL); fields = reader.m_fields; if (failedCreate) { if (result == RESULT_OK) { diff --git a/src/lib/ebus/test/test_filereader.cpp b/src/lib/ebus/test/test_filereader.cpp index b4386e13..cd58eee8 100755 --- a/src/lib/ebus/test/test_filereader.cpp +++ b/src/lib/ebus/test/test_filereader.cpp @@ -196,7 +196,13 @@ int main(int argc, char** argv) { size_t hash = 0, size = 0; time_t time = 0; string errorDescription; - result_t result = reader.readFromFile(argv[argpos], false, NULL, &errorDescription, &hash, &size, &time); + istream* stream = FileReader::openFile(argv[argpos], &errorDescription, &time); + result_t result; + if (!stream) { + result = RESULT_ERR_NOTFOUND; + } else { + result = reader.readFromStream(stream, argv[argpos], time, false, NULL, &errorDescription, &hash, &size); + } cout << argv[argpos] << " "; if (result != RESULT_OK) { cout << getResultCode(result) << ", " << errorDescription << endl; @@ -225,8 +231,7 @@ int main(int argc, char** argv) { vector row; string errorDescription; while (ifs.peek() != EOF) { - istringstream str; - result_t result = reader.readLineFromStream("", true, &ifs, &lineNo, &row, &errorDescription, &hash, &size); + result_t result = reader.readLineFromStream(&ifs, "", true, &lineNo, &row, &errorDescription, &hash, &size); if (result != RESULT_OK) { cout << " error " << getResultCode(result) << endl; error = true; @@ -266,8 +271,7 @@ int main(int argc, char** argv) { subDefaults.resize(1); subDefaults[0]["subcol 2"] = ";default of sub 0 subcol 2"; while (ifs.peek() != EOF) { - istringstream str; - result_t result = reader2.readLineFromStream("", true, &ifs, &lineNo, &row, &errorDescription, &hash, &size); + result_t result = reader2.readLineFromStream(&ifs, "", true, &lineNo, &row, &errorDescription, &hash, &size); if (result != RESULT_OK) { cout << " error " << getResultCode(result) << endl; error = true; diff --git a/src/lib/ebus/test/test_message.cpp b/src/lib/ebus/test/test_message.cpp index 056507c1..ce9fff2b 100755 --- a/src/lib/ebus/test/test_message.cpp +++ b/src/lib/ebus/test/test_message.cpp @@ -60,8 +60,24 @@ DataFieldTemplates* getTemplates(const string& filename) { } return templates; } + +result_t loadDefinitionsFromConfigPath(FileReader* reader, const string& filename, bool verbose, + map* defaults, string* errorDescription) { + time_t mtime = 0; + istream* stream = FileReader::openFile(filename, errorDescription, &mtime); + result_t result; + if (stream) { + result = reader->readFromStream(stream, filename, mtime, verbose, defaults, errorDescription); + delete(stream); + } else { + result = RESULT_ERR_NOTFOUND; + } + return result; } + +} // namespace ebusd + int main() { // message: [type],[circuit],name,[comment],[QQ[;QQ]*],[ZZ],[PBSB],[ID],fields... // field: name,part,type[:len][,[divisor|values][,[unit][,[comment]]]] @@ -170,12 +186,12 @@ int main() { istringstream dummystr("#"); string errorDescription; vector row; - templates->readLineFromStream(__FILE__, false, &dummystr, &lineNo, &row, &errorDescription, NULL, NULL); + templates->readLineFromStream(&dummystr, __FILE__, false, &lineNo, &row, &errorDescription, NULL, NULL); lineNo = 0; MessageMap* messages = new MessageMap(""); dummystr.clear(); dummystr.str("#"); - messages->readLineFromStream(__FILE__, false, &dummystr, &lineNo, &row, &errorDescription, NULL, NULL); + messages->readLineFromStream(&dummystr, __FILE__, false, &lineNo, &row, &errorDescription, NULL, NULL); vector< vector > defaultsRows; Message* message = NULL; vector mstrs; @@ -206,7 +222,7 @@ int main() { lineNo = baseLine + i; cout << "line " << (lineNo+1) << " "; if (isTemplate) { - result = templates->readLineFromStream(__FILE__, false, &isstr, &lineNo, &row, &errorDescription, NULL, NULL); + result = templates->readLineFromStream(&isstr, __FILE__, false, &lineNo, &row, &errorDescription, NULL, NULL); if (result != RESULT_OK) { cout << "\"" << check[0] << "\": template read error: " << getResultCode(result) << ", " << errorDescription << endl; @@ -220,7 +236,7 @@ int main() { } if (isstr.peek() == '*') { // store defaults or condition - result = messages->readLineFromStream(__FILE__, false, &isstr, &lineNo, &row, &errorDescription, NULL, NULL); + result = messages->readLineFromStream(&isstr, __FILE__, false, &lineNo, &row, &errorDescription, NULL, NULL); if (result != RESULT_OK) { cout << "\"" << check[0] << "\": default read error: " << getResultCode(result) << ", " << errorDescription << endl; error = true; @@ -302,7 +318,7 @@ int main() { } cout << "\"" << check[2] << "\": find OK" << endl; } else { - result = messages->readLineFromStream(__FILE__, false, &isstr, &lineNo, &row, &errorDescription, NULL, NULL); + result = messages->readLineFromStream(&isstr, __FILE__, false, &lineNo, &row, &errorDescription, NULL, NULL); if (failedCreate) { if (result == RESULT_OK) { cout << "\"" << check[0] << "\": failed create error: unexpectedly succeeded" << endl;