Skip to content

Commit 35bc831

Browse files
committed
test_dbc.cpp tests are now using new temporary file creation method
1 parent 386d29b commit 35bc831

1 file changed

Lines changed: 26 additions & 31 deletions

File tree

test/test_dbc.cpp

Lines changed: 26 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ TEST_CASE("Testing big endian, little endian") {
6767
SG_ Sig1 : 55|16@0- (0.1,0) [-3276.8|-3276.7] "C" Vector__XXX
6868
SG_ Sig2 : 39|16@1- (0.1,0) [-3276.8|-3276.7] "C" Vector__XXX)";
6969
const auto filename = create_temporary_dbc_with(dbc_contents.c_str());
70+
std::cerr << filename << std::endl;
7071

7172
auto parser = libdbc::DbcParser();
7273
parser.parse_file(filename.c_str());
@@ -85,16 +86,16 @@ TEST_CASE("Testing big endian, little endian") {
8586
}
8687

8788
TEST_CASE("Testing negative values") {
88-
const auto* filename = std::tmpnam(NULL);
89-
90-
create_tmp_dbc_with(filename, R"(BO_ 234 MSG1: 8 Vector__XXX
89+
std::string dbc_contents = PRIMITIVE_DBC + R"(BO_ 234 MSG1: 8 Vector__XXX
9190
SG_ Sig1 : 55|16@0- (0.1,0) [-3276.8|-3276.7] "C" Vector__XXX
9291
SG_ Sig2 : 39|16@0- (0.1,0) [-3276.8|-3276.7] "C" Vector__XXX
9392
SG_ Sig3 : 23|16@0- (10,0) [-3276.8|-3276.7] "C" Vector__XXX
94-
SG_ Sig4 : 7|16@0- (1,-10) [0|32767] "" Vector__XXX)");
93+
SG_ Sig4 : 7|16@0- (1,-10) [0|32767] "" Vector__XXX)";
94+
const auto filename = create_temporary_dbc_with(dbc_contents.c_str());
95+
std::cerr << filename << std::endl;
9596

9697
auto parser = libdbc::DbcParser();
97-
parser.parse_file(filename);
98+
parser.parse_file(filename.c_str());
9899

99100
REQUIRE(parser.get_messages().size() == 1);
100101
REQUIRE(parser.get_messages().at(0).name() == "MSG1");
@@ -131,13 +132,13 @@ TEST_CASE("Testing negative values") {
131132
}
132133

133134
TEST_CASE("Special characters in unit") {
134-
const auto* filename = std::tmpnam(NULL);
135-
136-
create_tmp_dbc_with(filename, R"(BO_ 234 MSG1: 8 Vector__XXX
137-
SG_ Speed : 0|8@1+ (1,0) [0|204] "Km/h" DEVICE1,DEVICE2,DEVICE3)");
135+
std::string dbc_contents = PRIMITIVE_DBC + R"(BO_ 234 MSG1: 8 Vector__XXX
136+
SG_ Speed : 0|8@1+ (1,0) [0|204] "Km/h" DEVICE1,DEVICE2,DEVICE3)";
137+
const auto filename = create_temporary_dbc_with(dbc_contents.c_str());
138+
std::cerr << filename << std::endl;
138139

139140
auto parser = libdbc::DbcParser();
140-
parser.parse_file(filename);
141+
parser.parse_file(filename.c_str());
141142

142143
REQUIRE(parser.get_messages().size() == 1);
143144
REQUIRE(parser.get_messages().at(0).name() == "MSG1");
@@ -149,15 +150,15 @@ TEST_CASE("Special characters in unit") {
149150
}
150151

151152
TEST_CASE("Signal Value Description") {
152-
const auto* filename = std::tmpnam(NULL);
153-
154-
create_tmp_dbc_with(filename, R"(BO_ 234 MSG1: 8 Vector__XXX
153+
std::string dbc_contents = PRIMITIVE_DBC + R"(BO_ 234 MSG1: 8 Vector__XXX
155154
SG_ State1 : 0|8@1+ (1,0) [0|200] "Km/h" DEVICE1,DEVICE2,DEVICE3
156155
SG_ State2 : 0|8@1+ (1,0) [0|204] "" DEVICE1,DEVICE2,DEVICE3
157-
VAL_ 234 State1 123 "Description 1" 0 "Description 2" 90903489 "Big value and special characters &$§())!" ;)");
156+
VAL_ 234 State1 123 "Description 1" 0 "Description 2" 90903489 "Big value and special characters &$§())!" ;)";
157+
const auto filename = create_temporary_dbc_with(dbc_contents.c_str());
158+
std::cerr << filename << std::endl;
158159

159160
auto parser = libdbc::DbcParser();
160-
parser.parse_file(filename);
161+
parser.parse_file(filename.c_str());
161162

162163
REQUIRE(parser.get_messages().size() == 1);
163164
REQUIRE(parser.get_messages().at(0).name() == "MSG1");
@@ -176,18 +177,15 @@ VAL_ 234 State1 123 "Description 1" 0 "Description 2" 90903489 "Big value and sp
176177
}
177178

178179
TEST_CASE("Signal Value Description Extended CAN id") {
179-
/*
180-
* It should not crash, even extended CAN id is used
181-
*/
182-
const auto* filename = std::tmpnam(NULL);
183-
184-
create_tmp_dbc_with(filename, R"(BO_ 3221225472 MSG1: 8 Vector__XXX
180+
std::string dbc_contents = PRIMITIVE_DBC + R"(BO_ 3221225472 MSG1: 8 Vector__XXX
185181
SG_ State1 : 0|8@1+ (1,0) [0|200] "Km/h" DEVICE1,DEVICE2,DEVICE3
186182
SG_ State2 : 0|8@1+ (1,0) [0|204] "" DEVICE1,DEVICE2,DEVICE3
187-
VAL_ 3221225472 State1 123 "Description 1" 0 "Description 2" 4000000000 "Big value and special characters &$§())!" ;)");
183+
VAL_ 3221225472 State1 123 "Description 1" 0 "Description 2" 4000000000 "Big value and special characters &$§())!" ;)";
184+
const auto filename = create_temporary_dbc_with(dbc_contents.c_str());
185+
std::cerr << filename << std::endl;
188186

189187
auto parser = libdbc::DbcParser();
190-
parser.parse_file(filename);
188+
parser.parse_file(filename.c_str());
191189

192190
REQUIRE(parser.get_messages().size() == 1);
193191
REQUIRE(parser.get_messages().at(0).name() == "MSG1");
@@ -206,22 +204,19 @@ VAL_ 3221225472 State1 123 "Description 1" 0 "Description 2" 4000000000 "Big val
206204
}
207205

208206
TEST_CASE("Signal Value Multiple VAL_") {
209-
/*
210-
* It should not crash, even extended CAN id is used
211-
*/
212-
const auto* filename = std::tmpnam(NULL);
213-
214-
create_tmp_dbc_with(filename, R"(BO_ 3221225472 MSG1: 8 Vector__XXX
207+
std::string dbc_contents = PRIMITIVE_DBC + R"(BO_ 3221225472 MSG1: 8 Vector__XXX
215208
SG_ State1 : 0|8@1+ (1,0) [0|200] "Km/h" DEVICE1,DEVICE2,DEVICE3
216209
SG_ State2 : 0|8@1+ (1,0) [0|204] "" DEVICE1,DEVICE2,DEVICE3"
217210
BO_ 123 MSG2: 8 Vector__XXX
218211
SG_ State1 : 0|8@1+ (1,0) [0|200] "Km/h" DEVICE1,DEVICE2,DEVICE3
219212
SG_ State2 : 0|8@1+ (1,0) [0|204] "" DEVICE1,DEVICE2,DEVICE3
220213
VAL_ 3221225472 State1 123 "Description 1" 0 "Description 2" ;
221-
VAL_ 123 State1 123 "Description 3" 0 "Description 4" ;)");
214+
VAL_ 123 State1 123 "Description 3" 0 "Description 4" ;)";
215+
const auto filename = create_temporary_dbc_with(dbc_contents.c_str());
216+
std::cerr << filename << std::endl;
222217

223218
auto parser = libdbc::DbcParser();
224-
parser.parse_file(filename);
219+
parser.parse_file(filename.c_str());
225220

226221
REQUIRE(parser.get_messages().size() == 2);
227222
REQUIRE(parser.get_messages().at(0).name() == "MSG1");

0 commit comments

Comments
 (0)