Skip to content

Commit bef3103

Browse files
committed
Clarifying test files that are used and added some more. The errors i am still thinking about and need to figure out how i might want to handle them.
1 parent 4ba5f8f commit bef3103

File tree

8 files changed

+135
-5
lines changed

8 files changed

+135
-5
lines changed

src/exceptions/error.hpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include <sstream>
12

23
namespace libdbc {
34

@@ -9,8 +10,25 @@ namespace libdbc {
910

1011
class validity_error : public exception {
1112
const char * what() const throw() {
12-
return "invalid file issue";
13+
return "Invalid DBC file...";
1314
}
1415
};
1516

17+
class header_error : public validity_error {
18+
header_error(const char* line, const char* expected, const char * file) :
19+
line(line), expected(expected), file(file) {}
20+
21+
const char * what() const throw() {
22+
std::ostringstream os;
23+
os << "Issue with the header line ( " << line << " ) in file ( ";
24+
os << file << " ). Expected to find: " << expected;
25+
return os.str().c_str();
26+
}
27+
28+
private:
29+
const char * line;
30+
const char * expected;
31+
const char * file;
32+
};
33+
1634
} // libdbc
File renamed without changes.

test/dbcs/MissingBitTiming.dbc

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
VERSION "1.0.0"
2+
3+
NS_ :
4+
BA_
5+
BA_DEF_
6+
BA_DEF_DEF_
7+
BA_DEF_DEF_REL_
8+
BA_DEF_REL_
9+
BA_DEF_SGTYPE_
10+
BA_REL_
11+
BA_SGTYPE_
12+
BO_TX_BU_
13+
BU_BO_REL_
14+
BU_EV_REL_
15+
BU_SG_REL_
16+
CAT_
17+
CAT_DEF_
18+
CM_
19+
ENVVAR_DATA_
20+
EV_DATA_
21+
FILTER
22+
NS_DESC_
23+
SGTYPE_
24+
SGTYPE_VAL_
25+
SG_MUL_VAL_
26+
SIGTYPE_VALTYPE_
27+
SIG_GROUP_
28+
SIG_TYPE_REF_
29+
SIG_VALTYPE_
30+
VAL_
31+
VAL_TABLE_
32+
33+
BU_: DBG DRIVER IO MOTOR SENSOR
34+
35+
BO_ 500 IO_DEBUG: 4 IO
36+
SG_ IO_DEBUG_test_unsigned : 0|8@1+ (1,0) [0|0] "" DBG

test/dbcs/MissingNewSymbols.dbc

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
VERSION "1.0.0"
2+
3+
NS_ :
4+
BA_
5+
BA_DEF_
6+
BA_DEF_DEF_
7+
BA_DEF_REL_
8+
BA_SGTYPE_
9+
BU_SG_REL_
10+
CAT_
11+
CAT_DEF_
12+
CM_
13+
ENVVAR_DATA_
14+
EV_DATA_
15+
FILTER
16+
SGTYPE_
17+
SG_MUL_VAL_
18+
SIGTYPE_VALTYPE_
19+
SIG_GROUP_
20+
SIG_TYPE_REF_
21+
VAL_
22+
VAL_TABLE_
23+
24+
BS_:
25+
26+
BU_: DBG DRIVER IO MOTOR SENSOR
27+
28+
BO_ 500 IO_DEBUG: 4 IO
29+
SG_ IO_DEBUG_test_unsigned : 0|8@1+ (1,0) [0|0] "" DBG

test/dbcs/MissingVersion.dbc

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
NS_ :
2+
BA_
3+
BA_DEF_
4+
BA_DEF_DEF_
5+
BA_DEF_DEF_REL_
6+
BA_DEF_REL_
7+
BA_DEF_SGTYPE_
8+
BA_REL_
9+
BA_SGTYPE_
10+
BO_TX_BU_
11+
BU_BO_REL_
12+
BU_EV_REL_
13+
BU_SG_REL_
14+
CAT_
15+
CAT_DEF_
16+
CM_
17+
ENVVAR_DATA_
18+
EV_DATA_
19+
FILTER
20+
NS_DESC_
21+
SGTYPE_
22+
SGTYPE_VAL_
23+
SG_MUL_VAL_
24+
SIGTYPE_VALTYPE_
25+
SIG_GROUP_
26+
SIG_TYPE_REF_
27+
SIG_VALTYPE_
28+
VAL_
29+
VAL_TABLE_
30+
31+
BS_:
32+
33+
BU_: DBG DRIVER IO MOTOR SENSOR
34+
35+
BO_ 500 IO_DEBUG: 4 IO
36+
SG_ IO_DEBUG_test_unsigned : 0|8@1+ (1,0) [0|0] "" DBG
File renamed without changes.

test/defines.hpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
#include <string>
22

3-
static const std::string TEXT_FILE = "./dbcs/TextFile.txt";
4-
static const std::string DBC_FILE_1 = "./dbcs/Sample1.dbc";
5-
static const std::string DBC_FILE_2 = "./dbcs/Sample2.dbc";
3+
// Correctly formated files
4+
static const std::string COMPLEX_DBC_FILE = "./dbcs/Complex.dbc";
5+
static const std::string SIMPLE_DBC_FILE = "./dbcs/Simple.dbc";
6+
7+
// Files with Errors
8+
static const std::string MISSING_NEW_SYMBOLS_DBC_FILE = "./dbcs/MissingNewSymbols.dbc";
9+
static const std::string MISSING_VERSION_DBC_FILE = "./dbcs/MissingVersion.dbc";
10+
static const std::string MISSING_BIT_TIMING_DBC_FILE = "./dbcs/MissingBitTiming.dbc";
11+
static const std::string TEXT_FILE = "./dbcs/TextFile.txt";

test/test_dbc.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,15 @@ TEST_CASE("Testing dbc file loading", "[fileio]") {
99
REQUIRE_THROWS_AS(parser->parse_file(TEXT_FILE), libdbc::validity_error);
1010
}
1111

12+
// Undecided on the type of error yet. Need to think about this.
13+
// SECTION("Loading a dbc with bad headers throws an error", "[error]") {
14+
// REQUIRE_THROWS_AS(parser->parse_file(MISSING_VERSION_DBC_FILE), libdbc::header_error);
15+
// }
16+
1217
SECTION("Loading a single simple dbc file", "[dbc]") {
1318
std::vector<libdbc::Message> messages;
1419

15-
parser->parse_file(DBC_FILE_2);
20+
parser->parse_file(SIMPLE_DBC_FILE);
1621

1722
REQUIRE(parser->get_version() == "1.0.0");
1823
}

0 commit comments

Comments
 (0)