Skip to content

Commit a666b52

Browse files
committed
add function create_tmp_dbc_with to simplify creating the dbc file
1 parent 8053bba commit a666b52

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

test/test_dbc.cpp

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11
#include <catch2/catch_test_macros.hpp>
22
#include "defines.hpp"
33
#include <libdbc/dbc.hpp>
4+
#include <string_view>
5+
6+
void create_tmp_dbc_with(const char* filename, const char* content)
7+
{
8+
auto* file = std::fopen(filename, "w");
9+
CHECK(file);
10+
11+
std::fputs(PRIMITIVE_DBC.c_str(), file);
12+
std::fputs(content, file);
13+
std::fclose(file);
14+
}
15+
416

517
TEST_CASE("Testing dbc file loading error issues", "[fileio][error]") {
618
auto parser = std::unique_ptr<libdbc::DbcParser>(new libdbc::DbcParser());
@@ -58,16 +70,11 @@ TEST_CASE("Testing dbc file loading", "[fileio]") {
5870
TEST_CASE("Testing negative values") {
5971
const auto* filename = std::tmpnam(NULL);
6072

61-
auto* file = std::fopen(filename, "w");
62-
CHECK(file);
63-
64-
std::fputs(PRIMITIVE_DBC.c_str(), file);
65-
std::fputs(R"(BO_ 234 MSG1: 8 Vector__XXX
73+
create_tmp_dbc_with(filename, R"(BO_ 234 MSG1: 8 Vector__XXX
6674
SG_ Sig1 : 55|16@0- (0.1,0) [-3276.8|-3276.7] "C" Vector__XXX
6775
SG_ Sig2 : 39|16@0- (0.1,0) [-3276.8|-3276.7] "C" Vector__XXX
6876
SG_ Sig3 : 23|16@0- (10,0) [-3276.8|-3276.7] "C" Vector__XXX
69-
SG_ Sig4 : 7|16@0- (1,-10) [0|32767] "" Vector__XXX)", file);
70-
std::fclose(file);
77+
SG_ Sig4 : 7|16@0- (1,-10) [0|32767] "" Vector__XXX)");
7178

7279
auto parser = libdbc::DbcParser();
7380
parser.parse_file(std::string(filename));
@@ -109,13 +116,9 @@ TEST_CASE("Testing negative values") {
109116
TEST_CASE("Special characters in unit") {
110117
const auto* filename = std::tmpnam(NULL);
111118

112-
auto* file = std::fopen(filename, "w");
113-
CHECK(file);
119+
create_tmp_dbc_with(filename, R"(BO_ 234 MSG1: 8 Vector__XXX
120+
SG_ Speed : 0|8@1+ (1,0) [0|204] "Km/h" DEVICE1,DEVICE2,DEVICE3)");
114121

115-
std::fputs(PRIMITIVE_DBC.c_str(), file);
116-
std::fputs(R"(BO_ 234 MSG1: 8 Vector__XXX
117-
SG_ Speed : 0|8@1+ (1,0) [0|204] "Km/h" DEVICE1,DEVICE2,DEVICE3)", file);
118-
std::fclose(file);
119122

120123
auto parser = libdbc::DbcParser();
121124
parser.parse_file(std::string(filename));

0 commit comments

Comments
 (0)