allow using newlines within quoted fields (special treat for @wfr2000)
This commit is contained in:
@@ -3,11 +3,15 @@ AM_CXXFLAGS = -fpic \
|
||||
-Wextra \
|
||||
-isystem$(top_srcdir)/src/lib/ebus
|
||||
|
||||
noinst_PROGRAMS = test_device \
|
||||
noinst_PROGRAMS = test_filereader \
|
||||
test_device \
|
||||
test_symbol \
|
||||
test_data \
|
||||
test_message
|
||||
|
||||
test_filereader_SOURCES = test_filereader.cpp
|
||||
test_filereader_LDADD = ../libebus.a
|
||||
|
||||
test_device_SOURCES = test_device.cpp
|
||||
test_device_LDADD = ../libebus.a
|
||||
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
* ebusd - daemon for communication with eBUS heating systems.
|
||||
* Copyright (C) 2014-2016 John Baier <ebusd@ebusd.eu>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "filereader.h"
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
|
||||
using namespace std;
|
||||
|
||||
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;
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
while (FileReader::splitFields(ifs, row, lineNo)) {
|
||||
cout << "line " << static_cast<unsigned>(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;
|
||||
continue;
|
||||
}
|
||||
for (vector<string>::iterator it = row.begin(); it != row.end(); it++) {
|
||||
string got = *it;
|
||||
string expect = resultline[distance(row.begin(), it)];
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -44,6 +44,8 @@ DataFieldTemplates* templates = NULL;
|
||||
|
||||
DataFieldTemplates* getTemplates(const string filename)
|
||||
{
|
||||
if (filename=="") // avoid compiler warning
|
||||
return templates;
|
||||
return templates;
|
||||
}
|
||||
|
||||
@@ -192,10 +194,12 @@ int main()
|
||||
continue;
|
||||
}
|
||||
}
|
||||
string item;
|
||||
vector<string> entries;
|
||||
|
||||
FileReader::splitFields(check[0], entries);
|
||||
istringstream ifs(check[0]);
|
||||
unsigned int lineNo = 0;
|
||||
if (!FileReader::splitFields(ifs, entries, lineNo)) {
|
||||
entries.clear();
|
||||
}
|
||||
|
||||
if (deleteMessages.size()>0) {
|
||||
for (vector<Message*>::iterator it = deleteMessages.begin(); it != deleteMessages.end(); it++) {
|
||||
|
||||
Reference in New Issue
Block a user