File tree Expand file tree Collapse file tree 2 files changed +46
-3
lines changed
Expand file tree Collapse file tree 2 files changed +46
-3
lines changed Original file line number Diff line number Diff line change 11#include " exceptions/error.hpp"
2+ #include " util/utils.hpp"
23
34namespace 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}
Original file line number Diff line number Diff line change 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}
You can’t perform that action at this time.
0 commit comments