Skip to content

Commit f5ac560

Browse files
committed
format checking a little bit better and starting to parse more of the file. i have version started but it is dumb.
1 parent 98b180c commit f5ac560

File tree

2 files changed

+46
-3
lines changed

2 files changed

+46
-3
lines changed

src/dbc.hpp

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "exceptions/error.hpp"
2+
#include "util/utils.hpp"
23

34
namespace libdbc {
45

@@ -7,16 +8,48 @@ namespace libdbc {
78
virtual ~Parser() = default;
89

910
virtual void parse_file(const std::string& file) = 0;
11+
12+
protected:
13+
14+
void verify_dbc_format(std::istream& file_stream) const {
15+
std::string line;
16+
17+
Utils::SafeString::get_line(file_stream, line);
18+
19+
if(line.find("VERSION") == std::string::npos) {
20+
throw validity_error();
21+
}
22+
}
1023
};
1124

1225
class DbcParser : public Parser {
1326
public:
1427
virtual ~DbcParser() = default;
1528

1629
virtual void parse_file(const std::string& file) final override {
17-
throw validity_error();
30+
std::ifstream s(file.c_str());
31+
std::string line;
32+
33+
verify_dbc_format(s);
34+
35+
while(!s.eof()) {
36+
Utils::SafeString::get_line(s, line);
37+
38+
}
39+
40+
}
41+
42+
std::string get_version() const {
43+
return "";
1844
}
1945

46+
private:
47+
48+
49+
};
50+
51+
struct Message {
52+
2053
};
2154

2255
}

test/test_dbc.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,19 @@
22
#include "defines.hpp"
33
#include "dbc.hpp"
44

5-
TEST_CASE("Load a simple 1 line message dbc", "[fileio]") {
5+
TEST_CASE("Testing dbc file loading", "[fileio]") {
66
auto parser = std::unique_ptr<libdbc::DbcParser>(new libdbc::DbcParser());
77

8-
REQUIRE_THROWS_AS(parser->parse_file(DBC_FILE_2), libdbc::validity_error);
8+
SECTION("Loading a non dbc file should throw an error", "[error]") {
9+
REQUIRE_THROWS_AS(parser->parse_file(TEXT_FILE), libdbc::validity_error);
10+
}
11+
12+
SECTION("Loading a single simple dbc file", "[dbc]") {
13+
std::vector<libdbc::Message> messages;
14+
15+
parser->parse_file(DBC_FILE_2);
16+
17+
REQUIRE(parser->get_version() == "");
18+
}
919

1020
}

0 commit comments

Comments
 (0)