aligned tests with latest FileReader changes

This commit is contained in:
john30
2018-04-08 13:48:52 +02:00
parent 000d68f3c2
commit bee1fc5b8a
4 changed files with 20 additions and 20 deletions
+4 -4
View File
@@ -70,7 +70,7 @@ class TestReader : public MappedFileReader {
return RESULT_OK; // leave it to DataField::create return RESULT_OK; // leave it to DataField::create
} }
result_t addFromFile(const string& filename, unsigned int lineNo, map<string, string>* row, result_t addFromFile(const string& filename, unsigned int lineNo, map<string, string>* row,
vector< map<string, string> >* subRows, string* errorDescription) override { vector< map<string, string> >* subRows, string* errorDescription, bool replace) override {
if (!row->empty() || subRows->empty()) { if (!row->empty() || subRows->empty()) {
cout << "read line " << static_cast<unsigned>(lineNo) << ": read error: got " cout << "read line " << static_cast<unsigned>(lineNo) << ": read error: got "
<< static_cast<unsigned>(row->size()) << "/0 main, " << static_cast<unsigned>(subRows->size()) << static_cast<unsigned>(row->size()) << "/0 main, " << static_cast<unsigned>(subRows->size())
@@ -118,7 +118,7 @@ int main() {
istringstream dummystr("#"); istringstream dummystr("#");
string errorDescription; string errorDescription;
vector<string> row; vector<string> row;
templates->readLineFromStream(&dummystr, "inline", false, &lineNo, &row, &errorDescription, NULL, NULL); templates->readLineFromStream(&dummystr, "inline", false, &lineNo, &row, &errorDescription, false, NULL, NULL);
const DataField* fields = NULL; const DataField* fields = NULL;
for (unsigned int i = 0; i < sizeof(checks) / sizeof(checks[0]); i++) { for (unsigned int i = 0; i < sizeof(checks) / sizeof(checks[0]); i++) {
string check[5] = checks[i]; string check[5] = checks[i];
@@ -156,7 +156,7 @@ int main() {
lineNo = 0; lineNo = 0;
dummystr.clear(); dummystr.clear();
dummystr.str("#"); dummystr.str("#");
result = reader.readLineFromStream(&dummystr, "inline", false, &lineNo, &row, &errorDescription, NULL, NULL); result = reader.readLineFromStream(&dummystr, "inline", false, &lineNo, &row, &errorDescription, false, NULL, NULL);
if (result != RESULT_OK) { if (result != RESULT_OK) {
cout << "\"" << check[0] << "\": reader header error: " << getResultCode(result) << ", " << errorDescription cout << "\"" << check[0] << "\": reader header error: " << getResultCode(result) << ", " << errorDescription
<< endl; << endl;
@@ -164,7 +164,7 @@ int main() {
continue; continue;
} }
lineNo = baseLine + i; lineNo = baseLine + i;
result = reader.readLineFromStream(&isstr, __FILE__, false, &lineNo, &row, &errorDescription, NULL, NULL); result = reader.readLineFromStream(&isstr, __FILE__, false, &lineNo, &row, &errorDescription, false, NULL, NULL);
fields = reader.m_fields; fields = reader.m_fields;
if (result != RESULT_OK) { if (result != RESULT_OK) {
+5 -5
View File
@@ -69,7 +69,7 @@ class TestReader : public MappedFileReader {
return RESULT_OK; // leave it to DataField::create return RESULT_OK; // leave it to DataField::create
} }
result_t addFromFile(const string& filename, unsigned int lineNo, map<string, string>* row, result_t addFromFile(const string& filename, unsigned int lineNo, map<string, string>* row,
vector< map<string, string> >* subRows, string* errorDescription) override { vector< map<string, string> >* subRows, string* errorDescription, bool replace) override {
if (!row->empty() || subRows->empty()) { if (!row->empty() || subRows->empty()) {
cout << "read line " << static_cast<unsigned>(lineNo) << ": read error: got " cout << "read line " << static_cast<unsigned>(lineNo) << ": read error: got "
<< static_cast<unsigned>(row->size()) << "/0 main, " << static_cast<unsigned>(subRows->size()) << static_cast<unsigned>(row->size()) << "/0 main, " << static_cast<unsigned>(subRows->size())
@@ -512,7 +512,7 @@ int main() {
istringstream dummystr("#"); istringstream dummystr("#");
string errorDescription; string errorDescription;
vector<string> row; vector<string> row;
templates->readLineFromStream(&dummystr, __FILE__, false, &lineNo, &row, &errorDescription, NULL, NULL); templates->readLineFromStream(&dummystr, __FILE__, false, &lineNo, &row, &errorDescription, false, NULL, NULL);
const DataField* fields = NULL; const DataField* fields = NULL;
for (unsigned int i = 0; i < sizeof(checks) / sizeof(checks[0]); i++) { for (unsigned int i = 0; i < sizeof(checks) / sizeof(checks[0]); i++) {
string check[5] = checks[i]; string check[5] = checks[i];
@@ -567,7 +567,7 @@ int main() {
} }
if (isTemplate) { if (isTemplate) {
lineNo = baseLine + i; lineNo = baseLine + i;
result = templates->readLineFromStream(&isstr, __FILE__, false, &lineNo, &row, &errorDescription, NULL, NULL); result = templates->readLineFromStream(&isstr, __FILE__, false, &lineNo, &row, &errorDescription, false, NULL, NULL);
if (result != RESULT_OK) { if (result != RESULT_OK) {
cout << "\"" << check[0] << "\": template read error: " << getResultCode(result) << ", " cout << "\"" << check[0] << "\": template read error: " << getResultCode(result) << ", "
<< errorDescription << endl; << errorDescription << endl;
@@ -579,7 +579,7 @@ int main() {
lineNo = 0; lineNo = 0;
dummystr.clear(); dummystr.clear();
dummystr.str("#"); dummystr.str("#");
result = reader.readLineFromStream(&dummystr, __FILE__, false, &lineNo, &row, &errorDescription, NULL, NULL); result = reader.readLineFromStream(&dummystr, __FILE__, false, &lineNo, &row, &errorDescription, false, NULL, NULL);
if (result != RESULT_OK) { if (result != RESULT_OK) {
cout << "\"" << check[0] << "\": read header error: " << getResultCode(result) << ", " << errorDescription cout << "\"" << check[0] << "\": read header error: " << getResultCode(result) << ", " << errorDescription
<< endl; << endl;
@@ -587,7 +587,7 @@ int main() {
continue; continue;
} }
lineNo = baseLine + i; lineNo = baseLine + i;
result = reader.readLineFromStream(&isstr, "", false, &lineNo, &row, &errorDescription, NULL, NULL); result = reader.readLineFromStream(&isstr, "", false, &lineNo, &row, &errorDescription, false, NULL, NULL);
fields = reader.m_fields; fields = reader.m_fields;
if (failedCreate) { if (failedCreate) {
if (result == RESULT_OK) { if (result == RESULT_OK) {
+5 -5
View File
@@ -73,8 +73,8 @@ static unsigned int baseLine = 0;
class NoopReader : public FileReader { class NoopReader : public FileReader {
public: public:
result_t addFromFile(const string& filename, unsigned int lineNo, vector<string>* row, result_t addFromFile(const string& filename, unsigned int lineNo, vector<string>* row, string* errorDescription,
string* errorDescription) override { bool replace) override {
return RESULT_OK; return RESULT_OK;
} }
}; };
@@ -98,7 +98,7 @@ class TestReader : public MappedFileReader {
return RESULT_ERR_EOF; return RESULT_ERR_EOF;
} }
result_t addFromFile(const string& filename, unsigned int lineNo, map<string, string>* row, result_t addFromFile(const string& filename, unsigned int lineNo, map<string, string>* row,
vector< map<string, string> >* subRows, string* errorDescription) override { vector< map<string, string> >* subRows, string* errorDescription, bool replace) override {
if (row->empty() || (m_expectedCols == 3) != subRows->empty()) { if (row->empty() || (m_expectedCols == 3) != subRows->empty()) {
cout << "read line " << static_cast<unsigned>(baseLine + lineNo) << ": read error: got " cout << "read line " << static_cast<unsigned>(baseLine + lineNo) << ": read error: got "
<< static_cast<unsigned>(row->size()) << "/3 main, " << static_cast<unsigned>(subRows->size()) << static_cast<unsigned>(row->size()) << "/3 main, " << static_cast<unsigned>(subRows->size())
@@ -231,7 +231,7 @@ int main(int argc, char** argv) {
vector<string> row; vector<string> row;
string errorDescription; string errorDescription;
while (ifs.peek() != EOF) { while (ifs.peek() != EOF) {
result_t result = reader.readLineFromStream(&ifs, "", true, &lineNo, &row, &errorDescription, &hash, &size); result_t result = reader.readLineFromStream(&ifs, "", true, &lineNo, &row, &errorDescription, false, &hash, &size);
if (result != RESULT_OK) { if (result != RESULT_OK) {
cout << " error " << getResultCode(result) << endl; cout << " error " << getResultCode(result) << endl;
error = true; error = true;
@@ -271,7 +271,7 @@ int main(int argc, char** argv) {
subDefaults.resize(1); subDefaults.resize(1);
subDefaults[0]["subcol 2"] = ";default of sub 0 subcol 2"; subDefaults[0]["subcol 2"] = ";default of sub 0 subcol 2";
while (ifs.peek() != EOF) { while (ifs.peek() != EOF) {
result_t result = reader2.readLineFromStream(&ifs, "", true, &lineNo, &row, &errorDescription, &hash, &size); result_t result = reader2.readLineFromStream(&ifs, "", true, &lineNo, &row, &errorDescription, false, &hash, &size);
if (result != RESULT_OK) { if (result != RESULT_OK) {
cout << " error " << getResultCode(result) << endl; cout << " error " << getResultCode(result) << endl;
error = true; error = true;
+6 -6
View File
@@ -62,7 +62,7 @@ DataFieldTemplates* getTemplates(const string& filename) {
} }
result_t loadDefinitionsFromConfigPath(FileReader* reader, const string& filename, bool verbose, result_t loadDefinitionsFromConfigPath(FileReader* reader, const string& filename, bool verbose,
map<string, string>* defaults, string* errorDescription) { map<string, string>* defaults, string* errorDescription, bool replace = false) {
time_t mtime = 0; time_t mtime = 0;
istream* stream = FileReader::openFile(filename, errorDescription, &mtime); istream* stream = FileReader::openFile(filename, errorDescription, &mtime);
result_t result; result_t result;
@@ -186,12 +186,12 @@ int main() {
istringstream dummystr("#"); istringstream dummystr("#");
string errorDescription; string errorDescription;
vector<string> row; vector<string> row;
templates->readLineFromStream(&dummystr, __FILE__, false, &lineNo, &row, &errorDescription, NULL, NULL); templates->readLineFromStream(&dummystr, __FILE__, false, &lineNo, &row, &errorDescription, false, NULL, NULL);
lineNo = 0; lineNo = 0;
MessageMap* messages = new MessageMap(""); MessageMap* messages = new MessageMap("");
dummystr.clear(); dummystr.clear();
dummystr.str("#"); dummystr.str("#");
messages->readLineFromStream(&dummystr, __FILE__, false, &lineNo, &row, &errorDescription, NULL, NULL); messages->readLineFromStream(&dummystr, __FILE__, false, &lineNo, &row, &errorDescription, false, NULL, NULL);
vector< vector<string> > defaultsRows; vector< vector<string> > defaultsRows;
Message* message = NULL; Message* message = NULL;
vector<MasterSymbolString*> mstrs; vector<MasterSymbolString*> mstrs;
@@ -222,7 +222,7 @@ int main() {
lineNo = baseLine + i; lineNo = baseLine + i;
cout << "line " << (lineNo+1) << " "; cout << "line " << (lineNo+1) << " ";
if (isTemplate) { if (isTemplate) {
result = templates->readLineFromStream(&isstr, __FILE__, false, &lineNo, &row, &errorDescription, NULL, NULL); result = templates->readLineFromStream(&isstr, __FILE__, false, &lineNo, &row, &errorDescription, false, NULL, NULL);
if (result != RESULT_OK) { if (result != RESULT_OK) {
cout << "\"" << check[0] << "\": template read error: " << getResultCode(result) << ", " << errorDescription cout << "\"" << check[0] << "\": template read error: " << getResultCode(result) << ", " << errorDescription
<< endl; << endl;
@@ -236,7 +236,7 @@ int main() {
} }
if (isstr.peek() == '*') { if (isstr.peek() == '*') {
// store defaults or condition // store defaults or condition
result = messages->readLineFromStream(&isstr, __FILE__, false, &lineNo, &row, &errorDescription, NULL, NULL); result = messages->readLineFromStream(&isstr, __FILE__, false, &lineNo, &row, &errorDescription, false, NULL, NULL);
if (result != RESULT_OK) { if (result != RESULT_OK) {
cout << "\"" << check[0] << "\": default read error: " << getResultCode(result) << ", " << errorDescription << endl; cout << "\"" << check[0] << "\": default read error: " << getResultCode(result) << ", " << errorDescription << endl;
error = true; error = true;
@@ -318,7 +318,7 @@ int main() {
} }
cout << "\"" << check[2] << "\": find OK" << endl; cout << "\"" << check[2] << "\": find OK" << endl;
} else { } else {
result = messages->readLineFromStream(&isstr, __FILE__, false, &lineNo, &row, &errorDescription, NULL, NULL); result = messages->readLineFromStream(&isstr, __FILE__, false, &lineNo, &row, &errorDescription, false, NULL, NULL);
if (failedCreate) { if (failedCreate) {
if (result == RESULT_OK) { if (result == RESULT_OK) {
cout << "\"" << check[0] << "\": failed create error: unexpectedly succeeded" << endl; cout << "\"" << check[0] << "\": failed create error: unexpectedly succeeded" << endl;